Help in cofirmation box using select tag

hi i have this script to pass a value using a select tag…but i want to add a confirmation box on the select tag so i tried the onchange i does show the box but does not pass the value it stay on the same page…

here is my script…thanks…

onchange=“javascript: var x=window.confirm(‘Transfer this value?’);if (!x) return(false);”


				<table BORDERCOLOR="#0B0B0B"  frame="box" cellpadding="0" cellspacing="0" frame="box"  class="display" id="example"> 
			<thead>
				<tr  >
					<th><a>Ticket No</a></th>
					<th><a>Create By</a></th>
					<th><a>Create Date</a></th>
					<th><a>Date Assigned</a></th>
					<th><a>Problem Description</a></th>
					<th><a>Transfer To</a></th>
					<th><a>Action</a></th>
				</tr>
			</thead>
			<tbody>
				<?php	foreach($Tickets as $Ticket){?>
							<tr class='GradeA'>
								<td class='center'><?php echo "<a href='ticketassign.php?idno={$Ticket['TickNo']}' title='View Ticket'>".$Ticket['TickNo']."</a>";?></td>
								<td class='center'><?php echo $Ticket['UserName'];?></td>
								<td class='center'><?php echo $Ticket['DateCreate']; ?></td>
								<td class='center'><?php echo $Ticket['DateAssign']; ?></td>
								<td class='center'><?php echo $Ticket['Category']." (".$Ticket['Subcat'].")"?></td>
								<td class='center'>
									<form action='Transfer.php' method='POST' style="float:left;">
									<input type='hidden' name='TicketNo' value='<?php echo $Ticket['TickNo'];?>' >
									<select name='TransferOption'   onchange='form.submit()'>
											<option value="0">Please Select</option>
											<?php foreach($AssignOptions as $TransferOption){ 
											echo "<option value='".$TransferOption['MISPIC']."'>".$TransferOption['MISPIC']."</option>";
											 } ?>	
									</select>				
									</form>
								</td>
								<td class='center'> <?php echo "<a href='ClosedTicketsupport.php?id={$Ticket['TickNo']}' onClick=\\"javascript: var x=window.confirm('Close this Ticket no ".$Ticket['TickNo']."?');if (!x) return(false);\\" title='Closed Ticket'>Closed</a>"?> </td>
							</tr>
					<?php }	?>
			</tbody>
			<tfoot>
				<tr >
					<th>Ticket No</th>
					<th>Create By</th>
					<th>Create Date</th>
					<th>Date Assigned</th>
					<th>Problem Description</th>
					<th>Transfer To</th>
					<th>Action</th>
				</tr>	    
			</tfoot>			
	</table>


Change form to have an id:

<form action='Transfer.php' method='POST' style="float:left;" id="form-<?php echo $Ticket['TickNo']; ?>">

then set onchange event to something like this:

onchange="if(confirm('Transfer this value?')) document.getElementById('form-<?php echo $Ticket['TickNo']; ?>').submit();"

Thanks for your help…It works so well…

Hi,

another question how can i get the value in the select tag…to echo out in confirmation box…

I suggest that you move your inline scripting event out from the middle of your HTML code, and in to a separate piece of javascript code instead. It’s a technique that CSS people long ago realized has many benefits, and it’s the same with scripting.

CSS in the head, content in the body, and javascript at the bottom, just before the </body> tag.


<html>
<head>
<link type="text/css" rel="stylesheet" src="style.css">
</head>

<body>
...
<script src="script.js"></script>
</body>
</html>


form.ticket {
    float:left;
}


<form class="ticket" action='Transfer.php' method="post">


function ticketSubmitHandler() {
    if (window.confirm('Transfer this value?')) {
        this.form.submit();
    }
}

var forms = document.getElementsByTagName('form'),
    i;
for (i = 0; i < forms.length; i += 1) {
    if (forms[i].className === 'ticket') {
        forms[i].onchange = ticketSubmitHandler;
    }
}

Those id values aren’t required, although they might be useful for some further development.

Every form field has a property called form which refers to the form that the field is contained in.
So with the select, you can just use this.form.submit() instead.

Thanks, didn’t know that!

Hi,

I tried your suggestion but i;am confuse and did not get the job done…by popping out the confirmation box and its necessary value…


<html>
<head>

	  <style type="text/css">
form.ticket {
    float:left;
}
</style>
</head>
<body id="dt_example">
<br/>
<br/>
<br/>
<p>
<table  BORDERCOLOR="#0B0B0B" border='1' bgcolor="#F5F5FA" width="95%"  align='center'>
<tr>
	<td >
		<img src='img/assignticket.png'>
	</td>
</tr>
<tr>
	<td align='center'>
		<div align='left' id="containerassign">
			<div id="demo">
				<table BORDERCOLOR="#0B0B0B"  frame="box" cellpadding="0" cellspacing="0" frame="box"  class="display" id="example"> 
			<thead>
				<tr  >
					<th><a title="Ticket Number">Ticket No</a></th>
					<th><a title="Ticket Create By">Create By</a></th>
					<th><a title="Ticket Create Date">Create Date</a></th>
					<th><a title="Date Assigned">Date Assigned</a></th>
					<th><a title="Problem Error">Problem Description</a></th>
					<th><a title="Transfer">Transfer To</a></th>
					<th><a title="User Action">Action</a></th>
				</tr>
			</thead>
			<tbody>
				<?php	foreach($Tickets as $Ticket){?>
							<tr class='GradeA'>
								<td class='center'><?php echo "<a href='ticketassign.php?idno={$Ticket['TickNo']}' title='View Ticket'>".$Ticket['TickNo']."</a>";?></td>
								<td class='center'><?php echo $Ticket['UserName'];?></td>
								<td class='center'><?php echo $Ticket['DateCreate']; ?></td>
								<td class='center'><?php echo $Ticket['DateAssign']; ?></td>
								<td class='center'><?php echo $Ticket['Category']." (".$Ticket['Subcat'].")"?></td>
								<td class='center'>
									<form action='Transfer.php' method='POST'  class="ticket" id="form">
									<input type='hidden' name='TicketNo' value='<?php echo $Ticket['TickNo'];?>' >
									<select name='TransferOption'   onchange='this.form.submit()'>
											<option value="0">Please Select</option>
											<?php foreach($AssignOptions as $TransferOption){ 
											echo "<option value='".$TransferOption['MISPIC']."'>".$TransferOption['MISPIC']."</option>";
											 } ?>	
									</select>				
									</form>
								</td>
								<td class='center'> <?php echo "<a href='ClosedTicketsupport.php?id={$Ticket['TickNo']}' onClick=\\"javascript: var x=window.confirm('Close this Ticket no ".$Ticket['TickNo']."?');if (!x) return(false);\\" title='Closed Ticket'>Closed</a>"?> </td>
							</tr>
					<?php }	?>
			</tbody>
			<tfoot>
				<tr >
					<th>Ticket No</th>
					<th>Create By</th>
					<th>Create Date</th>
					<th>Date Assigned</th>
					<th>Problem Description</th>
					<th>Transfer To</th>
					<th>Action</th>
				</tr>	    
			</tfoot>			
	</table>
			</div>
		</div>
	</td>	
</tr>
</table>
</p>
	<script>
function ticketSubmitHandler() {
    if (window.confirm('Transfer this value?')) {
        this.form.submit();
    }
}
 
var forms = document.getElementsByTagName("form"),
    i;
for (i = 0; i < forms.length; i += 1) {
    if (forms[i].className === 'ticket') {
        forms[i].onchange = ticketSubmitHandler;
    }
}
	</script>
</body>
<html>

i got it working now…but still i can’t my echo my value that i select in the option tag


<option value="0">Please Select</option>
											<?php foreach($AssignOptions as $TransferOption){ 
											echo "<option value='".$TransferOption['MISPIC']."'>".$TransferOption['MISPIC']."</option>";