syntax error whist trying to autosubmit form via javascript

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
coolin
Forum Newbie
Posts: 21
Joined: Sun Mar 16, 2008 1:44 pm

syntax error whist trying to autosubmit form via javascript

Post by coolin »

I'm finding it difficult to add any new code in javascript or php to a large php prewritten application I'm trying to tweak I think I can work out how to tweak so I get to autosubmit a form but keep getting error messages when parsing code so can't get too much further yet. With the following code I've tried adding a line but get error- unexpected '=' I also notice a lot of slashes are being used at this part of the program Please might anyone be able to point out why I could be getting Unexpected 'item' messages so much when my code looks good or even copied from within the same program for example

Code: Select all

>body .="<br /><input type=\"submit\" name=\"z\" ";
            //$this->body .= 
 
"onclick=\"return checksubmit(this)\"";
    
// added here//
onload=\"javascript&#058;document.forms("z").submit()\";
/ added end//
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: syntax error whist trying to autosubmit form via javascript

Post by Christopher »

The // only comments to the end of the line. Use /* ... */ to comment multiple lines:

Code: Select all

           //$this->body .= 
 
"onclick=\"return checksubmit(this)\"";
(#10850)
coolin
Forum Newbie
Posts: 21
Joined: Sun Mar 16, 2008 1:44 pm

Re: syntax error whist trying to autosubmit form via javascript

Post by coolin »

Thanks; this part was actually part of the pre-written code Ps let me give a better example php code except below:

Code: Select all

<br />
echo"hello";
</form>\n";
By me having just added echo"hello"; I'm getting an error as follows: Parse error: syntax error, unexpected T_STRING ,just can't figure out why this might happen
Otherwise the application runs fine
kryles
Forum Contributor
Posts: 114
Joined: Fri Feb 01, 2008 7:52 am

Re: syntax error whist trying to autosubmit form via javascript

Post by kryles »

you seem to be mixing php and html without telling the browser which is which

Code: Select all

 
<br />
<?php echo "hello </form>\n"; ?>
 
edit: forgot to close my php tag originally
Last edited by kryles on Mon Mar 31, 2008 4:13 pm, edited 1 time in total.
coolin
Forum Newbie
Posts: 21
Joined: Sun Mar 16, 2008 1:44 pm

Re: syntax error whist trying to autosubmit form via javascript

Post by coolin »

Thanks this simple answer has solves all! I just found it difficult to reference also how a \ before quotes can effectively switch between html & php due to the way a string is being quoted :mrgreen:
Post Reply