PDA

View Full Version : adios - thanks heaps but my problem is a little different


jaydee
10-13-2002, 05:11 AM
Hi adios,

Thanks so much for replying. Your help was much appreciated!!

However, my problem is a little bit different and your code didn't quite solve it.

You see, my problem is that I only want to display, in a new window, the details of the form that is selected when the user clicks its button. I dont want to display the details of all the forms.

Is there any way that I can determine which form has been selected when the user hits the button, and then open the window and only display those details?

Hope you can help. Thanks again!
Jaydee

adios
10-13-2002, 05:20 AM
<html>
<head>
<title>untitled</title>
<script type="text/javascript" language="javascript">

var HTML, msgBox = null;
function showdata(f) {
if (msgBox && !msgBox.closed) msgBox.close();
HTML = '';
HTML += '<html><head><title>Data Window</title>';
HTML += '<style type="text/css">';
HTML += 'body{font:200 11px arial;color:ivory;background:olive;overflow:auto;}';
HTML += 'input{font:200 11px arial;color:olive;background:ivory;width:36px;}';
HTML += '</style></head><body><br><div style="font-size:14px;text-align:center;">';
HTML += '&amp;#149; The Details &amp;#149;</div><br><hr>';
var el, e = 0;
while (el = f.elements[e++]) {
if (el.type != 'button')
HTML += '<b>' + el.name + ': </b>' + el.value + '<br>';
}
HTML += '<hr><div style="text-align:center;">';
HTML += '<form><input type="button" value="close" onclick="self.close()">';
HTML += '</form></div></body></html>';
msgBox = open('javascript:opener.HTML','displayWindow','left=300,top=150,width=180,height=200,scrollbars');
if (msgBox && !msgBox.closed) msgBox.focus();
}

</script>
</head>
<body bgcolor="beige">
<form name="demo">
<input type="hidden" name="author" value="Mr. jaydee">
<input type="text" name="title" size="24" value="How Green is Her Valley">
<input type="button" value="Details" onclick="showdata(this.form)">
</form>
<form name="demo">
<input type="hidden" name="author" value="Mrs. jaydee">
<input type="text" name="title" size="24" value="How Green is His Valley">
<input type="button" value="Details" onclick="showdata(this.form)">
</form>
</body>
</html>


...don't forget to clean this one up too....

jaydee
10-13-2002, 06:56 AM
Thanks adios for that code, it was great.

I thought I understood it but I'm still struggling a little.

I tried to add another function to the code that looked like this

form name="demo">
<input type="hidden" name="author" value="Mr. jaydee">
<input type="text" name="title" size="24" value="How Green is Her Valley">
<input type="button" value="Details" onclick="showdata(this.form)">

<script language="JavaScript"> -----added bits
showall(this.form);
</script> ----up to here

</form>

In the <head> section I put some more Javascript that looked like this:-

function showall(form) {
document.write(form.title.value);
}

I'm trying to get the title to print as well in the form section of my web page, but I keep getting an error message (title is null or not an object).

What am I doing wrong????

I'm so frustrated!!!

Cheers to anyone who can help!

adios
10-13-2002, 09:41 PM
First of all, document.write() is pretty unselective - it discards the entire current page (assuming the page is completed) and loads another.

Could you be clearer on what you want printed and where you want it printed?

adios

glenngv
10-14-2002, 02:57 AM
the problem is here:

<script language="JavaScript">
showall(this.form);
</script>

The keyword this is used to refer to the current object.
so using this.form is only applicable when inserting in a form element like button,textbox,textarea,etc

use this instead:

<script language="JavaScript">
showall(document.demo);
</script>

where demo is the name of your form.