Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with div's and form fields

Status
Not open for further replies.

cfdeveloper

Programmer
Nov 20, 2003
144
0
0
GB
Hi Everybody,
I really need a second opinion from someone on using DIV's. My page has a form with two div's, the first div, has two text fields and a button with a onClick event. When the user hits the button, the second div is displayed. Here's my code:

<html>
<head>
<title>DIV Example</title>

<style>
.normal{position:absolute;top:100px;left:100px;display:inline;}
.hidden{position:absolute;top:-200px;left:-200px;display:none;}
</style>

<script>
function pressedGo(){
if (document.getElementById(&quot;superDiv1&quot;).className == &quot;hidden&quot;){
document.getElementById(&quot;superDiv1&quot;).className = &quot;normal&quot;;
document.getElementById(&quot;superDiv&quot;).className = &quot;hidden&quot;;
}
}

</script>

</head>

<body>
<form name=&quot;frm&quot; method=&quot;post&quot;>
<table width=&quot;100%&quot; border=&quot;0&quot;>
<tr>
<td align=&quot;left&quot;>
<div id=&quot;superDiv&quot; style=&quot;position:absolute; z-index:2; top: 50px; left: 5px; border: 1px none #000000;&quot; class=&quot;normal&quot;>
<table width=&quot;100%&quot; border=&quot;0&quot;>
<tr>
<td align=&quot;left&quot;>
Enter user name <input type=&quot;text&quot; name=&quot;userName&quot;>&nbsp;or area&nbsp;
<input type=&quot;text&quot; name=&quot;area&quot;>
&nbsp;&nbsp; <input type=&quot;button&quot; name=&quot;go&quot; value=&quot;go&quot; onclick=&quot;pressedGo()&quot;>
</td>
</tr>
</table>
</div>
</td>
</tr>

<tr>
<td width=&quot;100%&quot; valign=&quot;top&quot;>
<div id=&quot;superDiv1&quot; style=&quot;position:absolute; z-index:2; top: 50px; left: 5px; border: 1px none #000000;&quot; class=&quot;hidden&quot;>
<table width=&quot;100%&quot; border=&quot;0&quot;>
<tr>
<td align=&quot;left&quot;>
<p><input type=&quot;text&quot; name=&quot;txtField1&quot;></p>
<p><input type=&quot;text&quot; name=&quot;txtField2&quot;></p>
<p><input type=&quot;text&quot; name=&quot;txtField3&quot;></p>
<p><input type=&quot;text&quot; name=&quot;txtField4&quot;></p>
</td></tr></table>
</div>
</td>
</tr>
</table>
</form>

</body>
</html>

The code above is fairly st8forward, I hope. What I want it to actually do is pass the usename form field value from div 1 and pass the value to a query in div 2 and display the user details in the div 2 text fields without
actually submitting the form. Is this possible? Is there any other way at all to do this sort of a thing?

Many Thanks
CF Developer
 
NOPE.

passing the form values will work great, but as soon as you need anything from the server (a query) the form MUST be submited to the server. you might be able to work around that by opening a hidden popup, sendin the data to the server, then putting that data into the original form page, but thats bloated coding in my opinion.

 
I know its not the best way of doing it, but it seems to me that this is the only option. Can you show me how open a hidden popup window which passes the data to the server and returns the data into the original form page?
 
first genereate your URL for the hidden window with the data in the url, use javascript to open a new window, you can use java script to also move the window off screen, or other ways to make it 'hidden'. that pop up takes the URL data (from the first form) and runs a query, gets results, pass those results into more javascript that past them into the original windows second form, and closes itself (or promts to be closed. 'click here to continue' or something)

But what i dont' get is why is it the only option? make a login page ('div' 1, two fields) send that off to the action page ('div' 2) it looks up the data, and displays it based on form variables from first form. very simple.

got to keep in mind that cold fusion and everything it does is ran on the server BEFORE the client gets the page. After its on the clients browser, it has nothing to do with the server anymore.

 
2 ways to do this...

You could use Iframes. You have the first form in a DIv in the parent page, and when you hit the button execute some JS that calls some CF page (with the username as part of the querystring) in the iframe which is inside the second, previously hidden div. I did this for a site and it worked well.

OR

when you hit the button, run a javascript function that does the following: takes the username as a parameter (or refers to it via the appropriate syntax of objects), makes the second div visible and uses 'document.all.secondHiddenLayer.innerHTML = sometextvar;' to write the contents of the hidden div. The code would be something like:

function showLayer() {
document.all.secondHiddenLayer.visibility = 'visible';
document.all.secondHiddenLayer.innerHTML = 'You submitted ' + document.all.username.value;
}
.
.
.
[form]
[input type=text name=username]
[input type=button onclick='showLayer();']
[/form]

notes:
[ should be the left angle bracket, and ] the right / closing one
Also, check out the javascript and dhtml forums (fora?)


HTH

Jon Daniels
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top