Click to See Complete Forum and Search --> : form problem
prof.frink
09-02-2004, 08:19 AM
Hi there...
I am looking for a script that makes a text-link open a popup window filled with a form. Now the tricky part: each link, should pass two values to a specific <input> inside the form in the popup. Like an inverse http://javascript.internet.com/forms/passing-values.html I don't have access to a server side language.
It would be great if someone knew a ready to use answer :-)
Charles
09-02-2004, 08:46 AM
How do you keep things working for those of us who do not use JavaScript?
prof.frink
09-02-2004, 09:15 AM
Originally posted by Charles
How do you keep things working for those of us who do not use JavaScript?
Hm, good point, but this is just an option, to make things more comfortable for users who do use javascript. Everyone will be able to make entrys without using javascript, yet they have to manually make entries themselves.
Charles
09-02-2004, 09:34 AM
What exactly are you trying to pass to the FORM?
How do you keep things working for those of us who do not use JavaScript?
..blah blah Why not:"How do you keep things working for those of us who do not use a computer at all?"
Man, it looks like you are hunting the javascript users, so I chose to hunting you whenever you are hunting them... This is a Javascript Forum, after all. I don't think it's fair to activate against thgis language... Go for it and support a language, will you?
prof.frink
09-02-2004, 10:00 AM
Two values, the name of a theatre play and the date. I have a table with all plays and dates, and an online-preorder-button at the end of each row. pressing this, a popup will open, with a form in it, where people can enter their name etc. And I think it would be neat, if the name of the play and date would already be filled in.
But I got something: I already can send data from a form to a popup, where it is displayed using document write.
index-file:
<form type="get" action="popup.htm" target="theWin" onsubmit="window.open('','theWin','height=200px,width=300px');">
<input type="hidden" name="title" value="name_of_the_play">
<input type="hidden" name="date" value="16.9.2004">
<input type="submit" value="preorder">
</form>
popup.htm:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>popup</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
function getParams() {
var idx = document.URL.indexOf('?');
var params = new Array();
if (idx != -1) {
var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
for (var i=0; i<pairs.length; i++) {
nameVal = pairs[i].split('=');
params[nameVal[0]] = nameVal[1];
}
}
return params;
}
params = getParams();
// End -->
</script>
</head>
<body>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
title = unescape(params["title"]);
date = unescape(params["date"]);
document.write(title + "<br>");
document.write(date);
// End -->
</script>
</body>
</html>
Now, how do I get the variables title & date into a defined form/input field?
Charles
09-02-2004, 10:19 AM
Originally posted by prof.frink
But I got something: I already can send data from a form to a popup, where it is displayed using document write. Bad, very bad. Then the people without JavaScript will be completely shut out. You want to link to a real page.
The best practice would be to have a separate FORM for each button.
The next best would be to parse the URL.
I'm working on an example …
Charles
09-02-2004, 10:41 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example</title>
</head>
<body>
<form action="test2.html" method="get" onsubmit="window.open('', 'child', 'height=400,width=300')" target="child">
<div>
<input type="hidden" name="foo" value="some foo">
<input type="hidden" name="bar" value="some bar">
<button type="submit">Submit</button>
</div>
</form>
</body>
</html>
And …
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<meta name="Content-Style-Type" content="text/css">
<title>Example</title>
<script type="text/javascript">
<!--
query = new Object();
for (i = 0; p = window.location.search.split('&')[i]; i++) {if (/\??(.*)=(.*)/.test(p)) query[unescape(RegExp.$1)] = unescape(RegExp.$2).replace(/\+/g, ' ')}
if (document.getElementById) onload = function () {
if (query.foo != null) document.getElementById('foo').value = query.foo;
if (query.bar != null) document.getElementById('bar').value = query.bar;
}
// -->
</script>
<style type="text/css">
<!--
form {width:10em}
fieldset {padding:1ex}
label {display:block; margin:1em 0}
input {display:block; width:9em}
button {display:block; margin:auto}
-->
</style>
</head>
<body>
<form action="someScript.pl">
<fieldset>
<legend>Example</legend>
<label>Foo<input id="foo" type="text"></label>
<label>Bar<input id="bar" type="text"></label>
<button type="submit">Submit</button>
</fieldset>
</form>
</body>
</html>
prof.frink
09-02-2004, 04:57 PM
Wow, thanks a lot. The script works alsobutely perfect. Great stuff. I think it would be a good idea, to post it at some javascript database. I didn't find anything like it and I spent hours searching.