/    Sign up×
Community /Pin to ProfileBookmark

How to use textarea value in self.location

Hi All,

I am a beginner in web programming, CGI and Javascript. I had to fix a bug in an already developed project.

It is a CGI script. There is a pull down menu (select), and onChange the self.location must use the text entered in the previous textarea field. If we use param method of CGI module, it represents the text literally and the javascript syntax is broken for each newline in the textarea value. On opening the script, the browser throws an error saying that ‘Unterminated string constant …”

To summarize, how do we represent a textarea value for self.location and use it back again.

Thanks in advance.
Tejo.

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliJan 13.2004 — why can't you submit the form to your CGI???

if you can then you should be able to get he textarea value(as many lines there may be) by getting the parameter(element name)

not sure if the above is correct syntax for CGI

if y ou must use location then explain more on how is javascript handling hte location data?

and finally,I hope it all made sense..:-)
Copy linkTweet thisAlerts:
@KorJan 13.2004 — Something like this? If I well understood...:

[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script>
function selfLoc(obj){
window.self.location = obj.options[obj.selectedIndex].text;
}
</script>
</head>

<body>
<form>
<select name="sel" onchange="selfLoc(this)">
<option>choose</option>
<option>http://www.cnn.com</option>
</select
></form>
</body>
</html>
[/code]
Copy linkTweet thisAlerts:
@KorJan 13.2004 — This forum consider my string as a href, so:

[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script>
function selfLoc(obj){
alert(obj.options[obj.selectedIndex].text);
window.self.location = obj.options[obj.selectedIndex].text;
}
</script>
</head>

<body>
<form>
<select name="sel" onchange="selfLoc(this)">
<option>choose</option>
<option>your_URL_here</option>
<option>your_other_URL_here</option>
</select
></form>
</body>
</html>
[/code]
Copy linkTweet thisAlerts:
@KorJan 13.2004 — and a return false if selectedIndex is 0, so:

[code=php]
<html>
<head>
<script>
function selfLoc(obj){
if(obj.selectedIndex == 0){
return false;
}
else {
window.self.location = obj.options[obj.selectedIndex].text;
}
}
</script>
</head>

<body>
<form>
<select name="sel" onchange="selfLoc(this)">
<option selected>choose</option>
<option>URL_here</option>
<option>URL2_here</option>
</select
></form>
</body>
</html>
[/code]


Insert your URL inside the options... I think you need to know the reference of the option's text... The long ref is:

document.form_name.selection_name.options[document.form_name.selection_name.selectedIndex].text
Copy linkTweet thisAlerts:
@tejovamsiauthorJan 13.2004 — Hi KOR,

Thanks a lot for your detailed reply, and yes it worked. I tried using the document.form_name notation and now I when I refresh, I am able to see the textarea properly.

Initially, I was not sure wheter this can be achieved by any perl routines or through Javascript ;-( Now I am able to proceed.

Thanks again.

Cheers,

Tejo.
×

Success!

Help @tejovamsi 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.1,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...