SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2011
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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);"

    Code HTML4Strict:
    				<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>

  2. #2
    Forums Designer
    Join Date
    Jun 2004
    Posts
    422
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change form to have an id:
    Code:
    <form action='Transfer.php' method='POST' style="float:left;" id="form-<?php echo $Ticket['TickNo']; ?>">
    then set onchange event to something like this:

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

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2011
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your help..It works so well..

  4. #4
    SitePoint Zealot
    Join Date
    Mar 2011
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

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

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,683
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ryoka012 View Post
    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.

    Code html4strict:
    <html>
    <head>
    <link type="text/css" rel="stylesheet" src="style.css">
    </head>
     
    <body>
    ...
    <script src="script.js"></script>
    </body>
    </html>

    Code css:
    form.ticket {
        float:left;
    }

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

    Code javascript:
    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;
        }
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,683
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by CyberAlien View Post
    document.getElementById('form-<?php echo $Ticket['TickNo']; ?>').submit();
    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.
    Last edited by paul_wilkins; May 27, 2011 at 03:45.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  7. #7
    Forums Designer
    Join Date
    Jun 2004
    Posts
    422
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    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!

  8. #8
    SitePoint Zealot
    Join Date
    Mar 2011
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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..

    Code HTML4Strict:
    <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>

  9. #9
    SitePoint Zealot
    Join Date
    Mar 2011
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i got it working now..but still i can't my echo my value that i select in the option tag

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


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •