0

I have a php code with this line:

<input id="sample" name="btnViewTutorial" type="button" />

and when clicked, a javascript would run:

var sampleButton = document.getElementById("sample");
sampleButton.onclick = function(){
    window.open ("/tutorials/sample.php", "mywindow","status=0,toolbar=0,height=480,width=600,directories=0");  
}

What i would like to do is, when the button is clicked, /tutorials/sample.php should have the value passed by the button, like tutorials/sample.php?video=1 or tutorials/sample.php?video=ff56gskkd2.

How would I have the button passed in a value? and How would java script receive the value?

4
  • how about using a form instead? Commented Nov 13, 2013 at 0:32
  • What you can do, is just append the value to the URL. Commented Nov 13, 2013 at 0:33
  • @DrixsonOseña i want the page to be like a pop up. Commented Nov 13, 2013 at 0:44
  • @Kao i wanted it to be dynamically possible. Commented Nov 13, 2013 at 0:44

1 Answer 1

1

You need to append the querystring to the url. For example, if value of a video is a data attribute you can do something like this:

<input id="sample" name="btnViewTutorial" type="button" value="View Tutorial" data-video="1"/>

And in Javascript:

var sampleButton = document.getElementById("sample");

sampleButton.onclick = function(){
    console.log(this.dataset.video);
    window.open ("/tutorials/sample.php?video="+ this.dataset.video,
                 "mywindow","status=0,toolbar=0,height=480,width=600,directories=0");  
}

Demo: http://jsfiddle.net/A65xg/

Sign up to request clarification or add additional context in comments.

2 Comments

Where did the dataset.video in the Javascript came from?
From data-video="1" attribute, you can read about custom data attributes here: whatwg.org/specs/web-apps/current-work/multipage/…*-attributes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.