jamesxg1 Posted September 19, 2009 Share Posted September 19, 2009 Hiya guy's, I have this, <?php while($det = mysql_fetch_array($Dets)) { if(isset($det['name']) && isset($_GET['busid'])) { //THIS BIT WORKS echo '<label class="description" for="element_11"><img src="images/green_tick.gif" width="18" height="18"> You have selected ' . $det['name'] . '.</label>'; echo '<input id="busid" name= "busid" class="element text" maxlength="255" size="8" value="' . $det['id'] . '" type="hidden"/>'; echo '<input id="busname" name= "busname" class="element text" maxlength="255" size="8" value="' . $det['name'] . '" type="hidden"/><div></div>'; } else { //THIS DONT (JAVASCRIPT:AUTOSUGGEST()) IS WHAT ISNT WORKING. echo '<label class="description" for="element_11">Type To Search: </label><div><input name="search-q" id="search-q" type="text" class="element text medium" value="" onkeyup="javascript:autosuggest()"/></div>'; } } ?> I have labeled the areas, would someone assist here on helping me please, Many thanks, James. Link to comment https://forums.phpfreaks.com/topic/174828-solved-how-do-i-make-javascript-work-inside-a-php-echo/ Share on other sites More sharing options...
ozestretch Posted September 19, 2009 Share Posted September 19, 2009 does it need to have 'javascript:' part? echo '<label class="description" for="element_11">Type To Search: </label><div><input name="search-q" id="search-q" type="text" class="element text medium" value="" onkeyup="autosuggest();" /></div>'; I also assume that actual function is coded somewhere I couldn't see Link to comment https://forums.phpfreaks.com/topic/174828-solved-how-do-i-make-javascript-work-inside-a-php-echo/#findComment-921346 Share on other sites More sharing options...
jamesxg1 Posted September 19, 2009 Author Share Posted September 19, 2009 Hiya dude, Yea crucial lol doesn't run otherwise lol, And lol yea it shows maybe abit too much information lmao , It works when i am not echoing it but when i do bang blows up in my face lol. Many thanks, James. Link to comment https://forums.phpfreaks.com/topic/174828-solved-how-do-i-make-javascript-work-inside-a-php-echo/#findComment-921350 Share on other sites More sharing options...
ozestretch Posted September 19, 2009 Share Posted September 19, 2009 Must be onClick that doesn't need it. Do you have variables in the function call? eg: onkeyup="autosuggest('var1',this.value);" Link to comment https://forums.phpfreaks.com/topic/174828-solved-how-do-i-make-javascript-work-inside-a-php-echo/#findComment-921353 Share on other sites More sharing options...
jamesxg1 Posted September 19, 2009 Author Share Posted September 19, 2009 Nope, Functions runs perfectly fine when i dont echo the input box but i have the diagnosis that it is the function that isn't being run because i am echoing it. Many thanks, James. Link to comment https://forums.phpfreaks.com/topic/174828-solved-how-do-i-make-javascript-work-inside-a-php-echo/#findComment-921355 Share on other sites More sharing options...
ozestretch Posted September 19, 2009 Share Posted September 19, 2009 have you tried to echo it only once? (one loop) Or does it fault regardless of single field use or multiple field use Link to comment https://forums.phpfreaks.com/topic/174828-solved-how-do-i-make-javascript-work-inside-a-php-echo/#findComment-921358 Share on other sites More sharing options...
jamesxg1 Posted September 19, 2009 Author Share Posted September 19, 2009 Faults, Because i am echoing it it doesn't even show the input box lol. Many thanks, James. Link to comment https://forums.phpfreaks.com/topic/174828-solved-how-do-i-make-javascript-work-inside-a-php-echo/#findComment-921359 Share on other sites More sharing options...
ozestretch Posted September 19, 2009 Share Posted September 19, 2009 Faults, Because i am echoing it it doesn't even show the input box lol. Many thanks, James. lmao, didn't mention it was not being displayed at all That line echo '<label class="description" for="element_11">Type To Search: </label><div><input name="search-q" id="search-q" type="text" class="element text medium" value="" onkeyup="javascript:autosuggest()"/></div>'; displays fine on my server... does this if(isset($det['name']) && isset($_GET['busid'])) { actually return false at any stage? Link to comment https://forums.phpfreaks.com/topic/174828-solved-how-do-i-make-javascript-work-inside-a-php-echo/#findComment-921362 Share on other sites More sharing options...
jamesxg1 Posted September 19, 2009 Author Share Posted September 19, 2009 Faults, Because i am echoing it it doesn't even show the input box lol. Many thanks, James. lmao, didn't mention it was not being displayed at all That line echo '<label class="description" for="element_11">Type To Search: </label><div><input name="search-q" id="search-q" type="text" class="element text medium" value="" onkeyup="javascript:autosuggest()"/></div>'; displays fine on my server... does this if(isset($det['name']) && isset($_GET['busid'])) { actually return false at any stage? Lmfao , Nope nothing lol, The if statement works i just cant seem to understand why the java isn't, I think and this is only a hunch but i think the enders might be muddled ( } ) and the else statement is in the wrong place , Many thanks, James. Link to comment https://forums.phpfreaks.com/topic/174828-solved-how-do-i-make-javascript-work-inside-a-php-echo/#findComment-921368 Share on other sites More sharing options...
ozestretch Posted September 19, 2009 Share Posted September 19, 2009 So the second choice of the else statement is returned at some point? <?php while($det = mysql_fetch_array($Dets)) { /* * we will change this to check it */ if(isset($somethingthatdoesnotexist)) { //THIS BIT WORKS - but wont now echo '<label class="description" for="element_11"><img src="images/green_tick.gif" width="18" height="18"> You have selected ' . $det['name'] . '.</label>'; echo '<input id="busid" name= "busid" class="element text" maxlength="255" size="8" value="' . $det['id'] . '" type="hidden"/>'; echo '<input id="busname" name= "busname" class="element text" maxlength="255" size="8" value="' . $det['name'] . '" type="hidden"/><div></div>'; } else { //THIS DONT (JAVASCRIPT:AUTOSUGGEST()) IS WHAT ISNT WORKING. /* * * THIS BIT IS ACTUALLY BEING OUTPUTTED RIGHT?? * lets check by changing something above ^^^^^^^^^^^ */ echo '<label class="description" for="element_11">Type To Search: </label><div><input name="search-q" id="search-q" type="text" class="element text medium" value="" onkeyup="javascript:autosuggest()"/></div>'; } } ?> Link to comment https://forums.phpfreaks.com/topic/174828-solved-how-do-i-make-javascript-work-inside-a-php-echo/#findComment-921374 Share on other sites More sharing options...
jamesxg1 Posted September 19, 2009 Author Share Posted September 19, 2009 Nothings being printed lmao. Many thanks, James. Link to comment https://forums.phpfreaks.com/topic/174828-solved-how-do-i-make-javascript-work-inside-a-php-echo/#findComment-921379 Share on other sites More sharing options...
jamesxg1 Posted September 19, 2009 Author Share Posted September 19, 2009 Anyone know how to fix this :S ? Many thanks, James. Link to comment https://forums.phpfreaks.com/topic/174828-solved-how-do-i-make-javascript-work-inside-a-php-echo/#findComment-921386 Share on other sites More sharing options...
jamesxg1 Posted September 19, 2009 Author Share Posted September 19, 2009 Bump. Link to comment https://forums.phpfreaks.com/topic/174828-solved-how-do-i-make-javascript-work-inside-a-php-echo/#findComment-921392 Share on other sites More sharing options...
ozestretch Posted September 19, 2009 Share Posted September 19, 2009 This works fine for me <?php $i=0; while($i<3) { /* * we will change this to check it */ if(isset($somethingthatdoesnotexist)) { //THIS BIT WORKS - but wont now echo '<label class="description" for="element_11"><img src="images/green_tick.gif" width="18" height="18"> You have selected ' . $det['name'] . '.</label>'; echo '<input id="busid" name= "busid" class="element text" maxlength="255" size="8" value="' . $det['id'] . '" type="hidden"/>'; echo '<input id="busname" name= "busname" class="element text" maxlength="255" size="8" value="' . $det['name'] . '" type="hidden"/><div></div>'; } else { //THIS DONT (JAVASCRIPT:AUTOSUGGEST()) IS WHAT ISNT WORKING. /* * * THIS BIT IS ACTUALLY BEING OUTPUTTED RIGHT?? * lets check by changing something above ^^^^^^^^^^^ */ $echo '<label class="description" for="element_11">Type To Search: </label><div><input name="search-q" id="search-q" type="text" class="element text medium" value="" onkeyup="javascript:autosuggest()"/></div>'; } $i++; } ?> so I guess you know where to look Link to comment https://forums.phpfreaks.com/topic/174828-solved-how-do-i-make-javascript-work-inside-a-php-echo/#findComment-921393 Share on other sites More sharing options...
jamesxg1 Posted September 19, 2009 Author Share Posted September 19, 2009 This works fine for me <?php $i=0; while($i<3) { /* * we will change this to check it */ if(isset($somethingthatdoesnotexist)) { //THIS BIT WORKS - but wont now echo '<label class="description" for="element_11"><img src="images/green_tick.gif" width="18" height="18"> You have selected ' . $det['name'] . '.</label>'; echo '<input id="busid" name= "busid" class="element text" maxlength="255" size="8" value="' . $det['id'] . '" type="hidden"/>'; echo '<input id="busname" name= "busname" class="element text" maxlength="255" size="8" value="' . $det['name'] . '" type="hidden"/><div></div>'; } else { //THIS DONT (JAVASCRIPT:AUTOSUGGEST()) IS WHAT ISNT WORKING. /* * * THIS BIT IS ACTUALLY BEING OUTPUTTED RIGHT?? * lets check by changing something above ^^^^^^^^^^^ */ $echo '<label class="description" for="element_11">Type To Search: </label><div><input name="search-q" id="search-q" type="text" class="element text medium" value="" onkeyup="javascript:autosuggest()"/></div>'; } $i++; } ?> so I guess you know where to look Nope nothing, not working lol. Jheez this script snippet is a nightmare lmao Link to comment https://forums.phpfreaks.com/topic/174828-solved-how-do-i-make-javascript-work-inside-a-php-echo/#findComment-921406 Share on other sites More sharing options...
ozestretch Posted September 19, 2009 Share Posted September 19, 2009 have you run the above code on its own page? I have and it executes the way it should. If so then I am out of ideas. Good luck Link to comment https://forums.phpfreaks.com/topic/174828-solved-how-do-i-make-javascript-work-inside-a-php-echo/#findComment-921407 Share on other sites More sharing options...
jamesxg1 Posted September 19, 2009 Author Share Posted September 19, 2009 I got it working , Thanks for your time and help dude much appreciated have a nice weekend mate, take care, Many many thanks, James. Link to comment https://forums.phpfreaks.com/topic/174828-solved-how-do-i-make-javascript-work-inside-a-php-echo/#findComment-921414 Share on other sites More sharing options...
ozestretch Posted September 19, 2009 Share Posted September 19, 2009 I was out of ideas at post#66 from me.... you posted with success on post #666 was it line 6 that was causing the issues? haha Glad you got it... what was it? PEBKAC? Link to comment https://forums.phpfreaks.com/topic/174828-solved-how-do-i-make-javascript-work-inside-a-php-echo/#findComment-921416 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.