javascript

in javascript, I want to find a way like below.

If value = 1 then
placeholder = dropdown
else
placeholder = textbox
end if

Is it possible in Javasript or jquery?

<placeholder></placeholder>
LVL 1
ITsolutionWizardAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Slick812Connect With a Mentor Commented:
@ ITsolutionWizard, You say that your question is the same, in your last comment. Because of my misunderstanding or "not familiar with" your term and use of what you call a -
       <placeholder></placeholder>
also not sure also about why you say that HTML5 is used and makes a difference for us to make a solution?
So sorry about my lack of understanding in this.

It may help us if you can describe the "steps" or methods, you need to have in your javascript function so that when a <select> is changed from 1 to another then a dropdown or textbox is placed in your web page.

You say this - "I am asking for a <place holder></place holder> in html so it is just like container."
I have not seen this <place holder> Tag used in a web page HTML, so I do not see what you may need.
So It would help us very much, if you can show us the exact "HTML" that you start with, where you have this <place holder> Tag used that will be changed to <select> (dropdown) if the chose select is changed to one.

Also, can you say if the "Dynamic" (not static) content of the inserted <select> and textbox is from your ASP server code?
0
 
ZvonkoSystems architectCommented:
The answer is simple: Yes, it is possible.

But it depends on what you wanna do.
If the "value" is coming from a user input checkbox then you have to disable and hide the one control and enable and show the other control.
On Submit the disabled form controls are not submitted.

So what is your scenario for this requirement?
0
 
ITsolutionWizardAuthor Commented:
the value came from the <select></select>

The <placeholder> should be generic. It is not necessary to do disabled or not disabled.
just like what i mentioned. value 1 show drop down value 2 show text box.

Is that clear ?

Thanks
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
ZvonkoSystems architectCommented:
That is clear but my question is: are you sure that you want to loose the text input or the dropdown selection when the user switches the selector value?

Therefor the most developer decide to have both controls on the form and enable the requested one as selected.

The "dynamic" approach has NO advantages, only difficulties. For example: where do you get the dropdown options when you have 50 states for selection?
0
 
ZvonkoSystems architectCommented:
This is an example that works but that I would not recommend:
<html>
<head>
<title>Zvonko &#42;</title>
<script>
function switchOption(theSel){
  $("inputArea").innerHTML = $("inputTemplate"+theSel.value).innerHTML;
}

function $(theId){
  return document.getElementById(theId);
}
</script>
</head>
<body>
<form>
<select name="userSel" onChange="switchOption(this)">
<option value="1">Text</option>
<option value="2">DropdownText</option>
</select>
<hr>
<span id="inputArea">
<input type="text" name="usrInput" >
</span>
<hr>
<input type="submit">
</form>
<form name="hiddenForm" style="display:none;">
<span id="inputTemplate1">
<input type="text" name="userInput" >
</span>
<span id="inputTemplate2">
<select name="userInput">
<option value="1">One</option>
<option value="2">Two</option>
<option value="2">Three</option>
</select>
</span>
</form>
</body>
</html>

Open in new window


I would prefer disabling and enabling hidden elements on same form area.
0
 
ITsolutionWizardAuthor Commented:
no. this is not what I am asking for. I am asking for a <place holder></place holder> in html so it is just like container. It can accept text box, drop down, and etc. based on the value it is provided.

Your code have static html text and select.
0
 
ZvonkoSystems architectCommented:
the placeholder needs the final code for the input or for the select.
where should that select field definition come from?
0
 
Slick812Commented:
???? ITsolutionWizard, I have read through this, and I am unable to see or get what you may mean by your using the -
"  a <place holder></place holder> in html  so it is just like container."

I do not believe that this will be an effective way (if you can do that), ?
What I would do is have an existing HTML element like <span> or <div>, , AS A CONTAINER that you dynamically load the "contents" into as a <select> or <textbox>,  if you have an empty
     <span id="dynamic"></span>
it will disappear, and in JS you can load something into the HTML for it -

document.getElementById("dynamic").innerHTML = '<select name="d">
<option value="a">1</option>
<option value="b">2</option>
</select>';
and it will show the <select> or anything you place in it correctly as DHTML

Although you possibly  can put some <place holder> in it to the HTML document, you would then have to find it and remove it, then you can get use the DOM to "create" a <select> and add options, then you would need to use an insert command to place that element,  hopefully, in the same place of the Document structure, where you removed the place holder, not so easy.
0
 
ZvonkoSystems architectCommented:
0
 
Slick812Commented:
@Zvonko, more than likely, but I hoped to separate a Place Holder from the change of HTML that most JS uses, did not think that ITsolutionWizard got that, ,  or was used to templates or other programming that uses place holders.
0
 
ITsolutionWizardAuthor Commented:
Guys, I know it may be not very easy. In the same case, I can do that in asp.net . Since my project is in html5 , that why I asked this question.

If you don't have solution or too hard for you. It is ok. But I have to keep the question as it.

Thanks
0
 
ZvonkoSystems architectCommented:
@ ITsolutionWizard: you are right, its too hard for me <|;-)
0
All Courses

From novice to tech pro — start learning today.