SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast robee's Avatar
    Join Date
    Aug 2003
    Location
    phils.
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question how can i pass the form name from php to javascript?

    hi...i've searched this thread about passing variables from php to javascript, but i didnt get anything that suit my problem...

    here's my php code:

    PHP Code:
    $form 'form1';

    $output.='a href="' .$url'" onClick="submitForm('.$form.');">'.$i.'</a>&nbsp;'
    and this is my javascript code:

    Code:
    <script language="JavaScript">
    function submitForm(formname) 
    {
    	var formname = document.forms['formname'];
    	formname.submit();
    }
    </script>
    it seems that the $form value is not passed to the function...but when i try to do this on my php code:

    PHP Code:
    onClick="document.forms[\'form1\'].submit();" 
    it works....but what i want is to put this code in a class so it would be reusable...can anyone help me how properly pass the form name to javascript function?? ..please!

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You don't really 'pass variables from php to javascript', you just use PHP to print whatever JS is needed to get the job done. This:
    PHP Code:
    var formname document.forms['formname']; 
    ...will simply use the string 'formname' to look up the Form object involved. You don't want a (string) literal, but a variable to pass the actual name:
    PHP Code:
    function submitForm(formname
    {
        var 
    form document.forms[formname];
        if (
    null != form)
            
    form.submit();

    ::: certified wild guess :::

  3. #3
    SitePoint Enthusiast robee's Avatar
    Join Date
    Aug 2003
    Location
    phils.
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ey sir, THANKS! it works! i've spent too many nights figuring it out... ..that bit of info bout passing literals is a big help .!! thank you very much


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
  •