/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] I’m new to javascript. please help with the simple form..

Hi all;

I just started to learn about javascript. I write this small form like this:

This is a form to let user choose different option (from a radio groups) and then it will generate the content.

[CODE]
<html>
<head>
<title>Untitled Document</title>
<script type=”text/javascript”>

function generateCode(formName, displayIn)
{
var script_path = “http://www.fastueux.com”;
var keywords = document.forms[formName].elements[“keywords”].value;

var the_code = “”;

the_code += “<a href=”http://www.mydomain.com”><img src=”” + keywords + “”/></a>nn”;

displayCode(displayIn, the_code);
}
function displayCode(displayIn, the_code)
{
var the_element = document.getElementById(displayIn);

the_element.value = “”;
the_element.value = the_code;
}

</script>
</head>

<body>

<form name=”displayResult” onsubmit=”return false;” action=”#”>

<textarea name=”embeddingCode” cols=”61″ rows=”5″ class=”anonym_textarea” id=”embeddingCode”></textarea>
<br /><br />
<input class=”anonym_FormSubmit” type=”button” name=”markAll” id=”markAll” value=”Select All” onclick=”document.displayResult.embeddingCode.select();” />

</form>
<br />
<form name=”anonymizerForm” onsubmit=”generateCode(‘anonymizerForm’, ’embeddingCode’); return false;” action=”#”>

<p>

<label>
<input type=”radio” name=”keywords” class=”anonym_input” id=”keywordsInput” value=”demo” />
Radio</label>
<br />
<label>
<input type=”radio” name=”keywords” class=”anonym_input” id=”keywordsInput” value=”demo1″ />
Radio</label>
<br />
<br />
<br />
</p>

<input type=”submit” id=”submitButton” value=”Generate Now” class=”anonym_FormSubmit” />

</form>

</body>
</html>

[/CODE]

But everytime i click on the generate button then it said “undefined”; if i create only one option then it is fine. But i want to have 2 or 3 options; which users only can choose one of them and the generate the content.

Can you guys please help me.

Thank you very much

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@PolyGreatJun 10.2007 — Is this what you are wanting?

[CODE]<html>
<head>
<title>Untitled Document</title>
<script type="text/javascript">


function generateCode(formName, displayIn)
{
var script_path = "http://www.fastueux.com";


for (var i=0; i < document.forms[formName].elements["keywords"].length; i++)
{
if (document.forms[formName].elements["keywords"][i].checked)
{
var radio_val = document.forms[formName].elements["keywords"][i].value;
}
}

var the_code = "";


the_code += "<a href="http://www.mydomain.com"><img src="" + radio_val + ""/></a>nn";

displayCode(displayIn, the_code);
}
function displayCode(displayIn, the_code)
{
var the_element = document.getElementById(displayIn);

the_element.value = "";
the_element.value = the_code;
}

</script>
</head>

<body>

<form name="displayResult" onsubmit="return false;" action="#">


<textarea name="embeddingCode" cols="61" rows="5" class="anonym_textarea" id="embeddingCode"></textarea>
<br /><br />
<input class="anonym_FormSubmit" type="button" name="markAll" id="markAll" value="Select All" onclick="document.displayResult.embeddingCode.select();" />

</form>
<br />
<form name="anonymizerForm" onsubmit="generateCode('anonymizerForm', 'embeddingCode'); return false;" action="#">


<p>

<label>
<input type="radio" name="keywords" class="anonym_input" id="keywordsInput" value="demo" />
Radio</label>
<br />
<label>
<input type="radio" name="keywords" class="anonym_input" id="keywordsInput" value="demo1" />
Radio</label>
<br />
<br />
<br />
</p>

<input type="submit" id="submitButton" value="Generate Now" class="anonym_FormSubmit" />


</form>

</body>
</html>[/CODE]
Copy linkTweet thisAlerts:
@micxuyauthorJun 11.2007 — wow thanks a lot
×

Success!

Help @micxuy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...