SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2007
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question How to get return values from Javascript to HTML?

    Hi,
    I've a Javascript function where i'm sending an return value. How do i capture this return value from HTML.

    My javascript func is as below:

    Code:
    function check()
    {
    var frm=document.forms.stream_selection
    sel_num = new Array();
    Parr = new Array();
    for(j=1;j<1000;j++)
    {
    	if(frm[j] != null)
    	{
    	  if(!frm[j].checked)
    	  {
    	      frm[0].checked=false
    	  }
    	  else
    	  {
    		Parr.push(j);
    		ParrStr=Parr.join(','); 
    		alert(Parr);
    	  }
      }
      
    }
    return(ParrStr);
    }
    My HTML call function is as below:

    Code:
    echo "<td><center><input name=\"sstreamname\" type=\"checkbox\" onclick=\"check():return true;\"></center></td></tr></font></center></tr></font></center>";
    How do i get the value of ParrStr and transfer this to next form. I'm using PHP .

    Thanks,
    Ramki.

  2. #2
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you are processing the submit using php (action="myscript.php") you have access to all the form data

    one way to transfer it from js/html to php is to store it in the value attribute of a hidden input field then process it from the submitted form - but since it looks like the value is setting a checkbox you can just examine it's value attribute - then populate a session variable as required

    I don't think that you can examine the state of the checkbox with php without submitting the form or using ajax

  3. #3
    SitePoint Zealot
    Join Date
    Oct 2007
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by loquacity View Post
    If you are processing the submit using php (action="myscript.php") you have access to all the form data

    one way to transfer it from js/html to php is to store it in the value attribute of a hidden input field then process it from the submitted form - but since it looks like the value is setting a checkbox you can just examine it's value attribute - then populate a session variable as required

    I don't think that you can examine the state of the checkbox with php without submitting the form or using ajax
    I did what you said and was trying to access it it next page using REQUEST as below:

    Code:
    $Parr_Str=$_REQUEST["ParrStr"];
    $sel_num=split(",", $Parr_Str);
    $i=0;
    while ($i < count($sel_num)) 
    {
       echo "Yup";
       echo "$sel_num[$i]<br>";
       $i++;
    }
    I'm using form variable as :

    Code:
    <form name="stream_selection" enctype="multipart/form-data" method="post" action="selected_streams.php">
    and using input variable hidden and javascript function as below:

    Code:
    document.getrElementById('ParrStr').value=ParrStr;
    
    <input type="hidden" name="ParrStr" id="ParrStr"/>
    I'm able to see only Yup on screen. and i'm unable to see the values of ParrStr. the page is blank! Any help?

    Regards,
    Ramki.

  4. #4
    SitePoint Zealot
    Join Date
    Oct 2007
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The page is giving me an error of

    Object doen't support this property or method for the below line.

    Code:
    document.getrElementById('ParrStr').value=ParrStr;
    Whats this error?

    Thanks,
    Ramki.

  5. #5
    SitePoint Member GreboGuru's Avatar
    Join Date
    Jun 2006
    Location
    Wensleydale, UK
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You got and extra r in getElementById()

    Code:
    document.getrElementById('ParrStr').value=ParrStr;
    Is lunch here?


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
  •