473,326 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Changing HTML Input type

52
I'm trying to put together a form and so far it's been all ASP coding, now i wanna make it a bit more dynamic, but i'm kinda new to Javascript. so i hope you guys can help me.

What i have now is a form that consists of 2 inputs a drop down box and a text field. I want to have an onchange event on the drop down box so if you choose a certain option it will remove the text box and replace it with another drop down box.

First of all... will this be possible with Javascript?

second... I have the replacement drop down box currently stored in an ASP variable, will I be able to use that?

Any help or suggestions that might point me in the right direction will be appreciated :)
Jul 5 '07 #1
5 1576
gits
5,390 Expert Mod 4TB
hi ...

of course ... that is possible ;) ... only create all controls you need (including the dropddown) in your html-page ... then set the style of the elements you don't want to be displayed to hidden and the ones of the nodes you want to have displayed to visible. use style="display: none;" -> hidden or style="display: block" -> visible for that or use dom-methods like removeChild(), appendChild() or insertBefore(). try something and post some code ... so we may help you with particular problems ...

kind regards
Jul 6 '07 #2
Shisou
52
okay... I guess my brain was stuck in ASP mode where you can write the HTML code and have it appear... for Javascript I want to do something like this...

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function Switch
  3. {
  4. if (drop1 = "something")
  5. {
  6. ??? style = 'display='none''
  7. ??? style = 'display='block''
  8. }
  9. else
  10. {
  11. ??? style = 'display='block''
  12. ??? style = 'display='none''
  13. }
  14. }
  15. </script>
  16.  
  17. <select name="Drop1"
  18.  
  19. <input name="Text" style="display="block"">
  20. <select name="Drop2" style="display="none"">
  21.  
what function or syntax would i use to change the style on the input and select?

p.s.
Thank you for your help, i really appreciate it :)
Jul 6 '07 #3
acoder
16,027 Expert Mod 8TB
You can't use the same quote within another one, i.e. you can't use double quotes within double without escaping it with the backslash character. In your case, it would be easier to mix the single and double quotes.

In CSS styles, you define a style like this:
Expand|Select|Wrap|Line Numbers
  1. style="display:block"
Pass the select object to the function:
Expand|Select|Wrap|Line Numbers
  1. onchange="Switch(this)"
You may want to change the name of the function to possibly avoid reserved words.

To access the elements, either use the form elements array or give them ids and use document.getElementById.
Jul 7 '07 #4
Shisou
52
Thank you for your help!

I actually used

style.display = ...

but you definately lead me in the right direction.

Thanks again!
Jul 10 '07 #5
acoder
16,027 Expert Mod 8TB
Thank you for your help!

I actually used

style.display = ...

but you definately lead me in the right direction.

Thanks again!
You're welcome. Yes, style.display would set it using Javascript. And, come to think of it, you're right. You weren't using CSS there anyway.
Jul 11 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Csaba2000 | last post by:
I want to be able to programatically click on the center of an <INPUT type=image ...> element (I only care about IE 5.5+). This should work regardless of whether IE has focus. Normally you would...
3
by: Perdit | last post by:
I am wondering why this does not work in javascript. The html color is set to automatic (none) element1, element2, etc are input fields (textboxes) ...
4
by: j.t.w | last post by:
Hi All. I'm having a problem with my Date of Birth textbox. When I open the ..htm file, the "DoB" textbox is flat with a border. All of my other textboxes are sunken and are yellow. When I...
1
by: Arvind P Rangan | last post by:
Hi All, You must have used <input type="file"> in HTML very often. Is there any object or example done on this, other than using a text box and a button which will open with Directory Object. ...
17
by: Alan Silver | last post by:
Hello, I have a page which I am converting to use themes. The page has an HTML <input type="image"> element that is used to post to another page. I would like to replace this with a server...
2
by: Alan Silver | last post by:
Hello, If I have the following HTML... <input type="image" src="fred.gif"> .... is there a way to specify the image in CSS rather than in the HTML? TIA
3
by: Taras_96 | last post by:
Hi everyone, I've got a rather unconventional architecture that I'm having problems with... I have a form called "searchForm", that has an input of type "submit" (with name = "submitButton...
2
by: jon | last post by:
Hi This might be an easy one to answer but I have a web form in an ASP.NET 1.1 application with a hand-rolled HTML image button as follows which opens a help guide in a new window: <input...
1
by: sandeep kumar shah | last post by:
Hi, We have used a file uploading HTML tag in an HTML page. We need to customize the text displayed on the Button (which is by default “Browse…” for internet explorer). Below is the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.