sw9 Posted July 31, 2007 Share Posted July 31, 2007 Hi All, I am trying to auto-tab to different field elements using a javascript function, but it's not working and I think it's related to my PHP. Have been trying to fix this without any luck, so I'm stumped...Was hoping you might take a look and tell me what's wrong with my code...much appreciated in advance! Here is the javascript piece (a snippet I found): <script> /* Auto tabbing script- By JavaScriptKit.com http://www.javascriptkit.com This credit MUST stay intact for use */ function autotab(original,destination){ if (original.getAttribute&&original.value.length==original.getAttribute("maxlength")) destination.focus() } </script> That script works fine if I put this in the page: <b>Enter your 10-digit phone number:</b> <form name="sampleform"> <input type="text" name="first" size=4 onKeyup="autotab(this, document.sampleform.second)" maxlength=3> <input type="text" name="second" size=4 onKeyup="autotab(this, document.sampleform.third)" maxlength=3> <input type="text" name="third" size=5 maxlength=4> </form> However, when I try to use it for my actual code, nothing happens. I get an error that "cueM does not have any properties". Here is my code that calls the script: <form name="starttime" method="post" action="starttime_process.php"> <?php $cue_data = array(); $chapter_data = array(); while( $data = mysql_fetch_assoc( $rval ) ){ $cue_data[sizeof($cue_data)] = $data["cue"]; $chapter_data[sizeof($chapter_data)] = $data["chapter_name"]; } // End While // If there are existing cue points, show enough entry boxes for all of them if($rows >= $_POST["chapters"]){ $inserts = $rows; }else{ $inserts = $_POST["chapters"]; } for($i=0;$i<$inserts;$i++){ // echo substr($cue_data[$i], 0,2).":".substr($cue_data[$i], 2,2).":".substr($cue_data[$i],4,2)."<br>"; ?> <td class="text"> CUE[<?php echo $i + 1; ?>]: <?php // HERE IS WHERE I CALL THE SCRIPT! ?> <input type="text" name="cueH[<?php echo $i; ?>]" size=3 id="cueH_<?php echo $i; ?>" onKeyup="autotab(this, document.starttime.cueM[<?php echo $i;?>])" maxlength=2 value="<?php echo isset( $cue_data[$i] )?substr($cue_data[$i],0,2):""; ?>"> <input size="3" type="text" name="cueM[<?php echo $i; ?>]" id="cueM_<?php echo $i; ?>" value="<?php echo isset( $cue_data[$i] )?substr($cue_data[$i],2,2):""; ?>"> <input size="3" type="text" name="cueS[<?php echo $i; ?>]" id="cueS_<?php echo $i; ?>" value="<?php echo isset( $cue_data[$i] )?substr($cue_data[$i],4,2):""; ?>"></td><td class="text"> Chapter[<?php echo $i + 1; ?>]: <input size="40" type="text" name="chapter[<?php echo $i; ?>]" id="chapter_<?php echo $i; ?>" value="<?php echo isset( $chapter_data[$i] )?$chapter_data[$i]:""; ?>"></td></tr> <?php } // End For ?> I have a feeling this may be something stupid that I'm missing...Again, I would really appreciate any help! Link to comment https://forums.phpfreaks.com/topic/62674-phpjavascript-error-for-autotab/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.