3

I have a javascript snippet:

<script language="JavaScript" type="text/javascript" src="/partner/display.php?token=id"></script>

It's from the affiliate program we use, iDevaffiliate.

When included in the html of a page, it reads a value (the affiliate id) to the page, so the visitor can see it.

I need to get this same value inserted into to a hidden form field such as:

<input type="hidden" name="affid" id="affid"" value="value goes here">

This will allow us to submit the affiliate id in the form as a hidden value.

Any suggestion on how to include the value outputed by the javascript snippet as a value into the hidden form field?

The script itself doesn't work as a value in the form, atleast when I tried it in different ways. Thanks for any help.

Here is example page with js in the page, and a sample form. The value -100 should be created and visible when viewing the page (from the js): http://www.lifeleap.org/100-1-3-19.html

After Help and More Research, This Is What I Have So Far:

Script prints value here: <div id="affjs"><script language="JavaScript" type="text/javascript" src="/partner/display.php?token=id"></script></div>

<script type="text/javascript">
$('#testform').submit(function () {
var outputValue=document.getElementById("affjs").innerHTML;
document.getElementById("aff").value=outputValue;
});
</script>

<form method="post" action="/scripttest3.php" id="testform">
<input type="hidden" name="aff" id="aff" value="">
<button type="submit" value="Submit">Submit</button>
</form>

It's not finished, but I think I'm on the right track. Maybe onsubmit script needs to be included inside form? Thanks for any suggestions.

7
  • Maybe on form submit click button read the dom, take the data and put it into a hidden input Commented Dec 12, 2014 at 9:29
  • Do you have a recommendation on where I can learn more about accomplishing this? Maybe see an example? thanks. Commented Dec 12, 2014 at 9:32
  • I suggest you to use Jquery for semplicity. That said with jquery you can access thing easy, it depends however on what html it's printed by iDevaffiliate Commented Dec 12, 2014 at 9:34
  • The only thing the javascript prints is a number value, such as 110. Our WordPress site already loads jquery. Any suggestions on where I could go (web tutorial, etc) to learn how to do such a thing? Commented Dec 12, 2014 at 9:37
  • Do you print it inside an html tag? If yes can you add it to your question? Commented Dec 12, 2014 at 9:38

2 Answers 2

2

You will need to find the value in the DOM and then store in your hidden input field.

var outputValue=document.getElementById("id-of-html-tag-where-output-value-is").innerHTML;
document.getElementById("id-of-hidden-input-field").value=outputValue;

You should do this on form submit.

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

3 Comments

In firefox, in firebug, when I click on the script in the html pane, there are hundreds of different values in the dom pane. Some seem to be associated with script, and some do not. Any idea on how to find the correct value to use in the example you provided?
The easiest way would be, if you can view the value on the page, right click on it and then Inspect will show you the HTML tag container for it. If you don't know where in the page it is, you can use Firebug to trace the partner library and check where it prints the value.
If you use the following link, I have it set to create a value and print the value on the page (value is -100). When inspecting, I don't believe there is a specific html tag container for the script, but I guess I can easily create one. Would the code you first included be in the form or the js? Thanks, and here is the link: lifeleap.org/100-1-3-19.html
0

Inside the Javascript you can use like this

document.getElementById("affid").value ='value goes here' ;

Comments

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.