Page 1 of 1

syntax error whist trying to autosubmit form via javascript

Posted: Sun Mar 30, 2008 8:33 pm
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//

Re: syntax error whist trying to autosubmit form via javascript

Posted: Sun Mar 30, 2008 9:25 pm
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)\"";

Re: syntax error whist trying to autosubmit form via javascript

Posted: Mon Mar 31, 2008 7:37 am
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

Re: syntax error whist trying to autosubmit form via javascript

Posted: Mon Mar 31, 2008 7:54 am
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

Re: syntax error whist trying to autosubmit form via javascript

Posted: Mon Mar 31, 2008 2:52 pm
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: