I have a problem with disappearing "dynamic" form fields! (html + jquery) - html

I am currently working on a form, within a modal.
My objective is to implement dynamic fields that the user can add and remove.
*its also worth mentioning that the value of these "dynamic fields" later will be exported to a
firebase database!
For now the fields show up but, when i execute the delete/remove function to a recently
added field everything disapears.
This is the html section
<div class="bg-modal">
<div class="modal-contents">
<div class="close li:hoover">+</div>
<!-- validation todo -->
<form class="input-modal" id="kundInfo">
<br>
<input class="input-modal" type="text" placeholder="name" id="userName" required>
<input class="input-modal" type="email" placeholder="e-mail" id="userEmail" required>
<textarea class="input-modal" name="meddelande" placeholder="Övrig information" id="userMessage"></textarea>
<select class="input-modal" id="deliveryTown" value="">
<option value="default">Välj leveransort</option>
<option value="Stockholm">Stockholm</option>
<option value="Göteborg">Göteborg</option>
<option value="Kalmar">Kalmar</option>
</select>
<br>
<div id="dynamic-items">
<input class="dynamic-input-fields" type="text" name="artikel[]" placeholder="Artikel">
<input class="dynamic-input-fields" type="number" name="kvantitet[]" placeholder="kvantitet">
<input class="dynamic-input-fields" type="button" value="Lägg till" id="add">
<!-- (original submit button)
<input type="submit" value="submit">
-->
</div>
<br>
<select class="input-modal" id="produktKategori" value="">
<option value="default">Välj inköpskategori</option>
<option value="trävaror">Trävaror</option>
<option value="mur&puts">Mur & puts</option>
<option value="mark&trädgård">Mark & trädgård</option>
<option value="vvs">VVS</option>
<option value="våtrum">Våtrum</option>
<option value="verktyg">Verktyg</option>
</select>
<br>
<br>
<button class="input-modal" id="Skicka" type="submit">Skicka</button>
</form>
<div class="alert">Ditt förfrågan är skickad!</div>
</div>
</div>
...and this is the jquery file:
$(document).ready(function(){
$("#add").click(function (e){
event.preventDefault()
$('#dynamic-items').append(
'<input class="dynamic-input-fields" type="text" name="artikel[]" placeholder="Artikel">'+
'<input class="dynamic-input-fields" type="number" name="kvantitet[]" placeholder="kvantitet">'+
'<input type="button" name="delete[]" value="delete" id="delete"/></div>'
);
});
$('body').on('click', '#delete',function (e){
event.preventDefault()
$(this).parent('div').remove();
});
});

The html string not have <div> on start.
$(document).ready(function() {
$("#add").click(function(e) {
event.preventDefault()
$('#dynamic-items').append(
'<div><input class="dynamic-input-fields" type="text" name="artikel[]" placeholder="Artikel">' +
'<input class="dynamic-input-fields" type="number" name="kvantitet[]" placeholder="kvantitet">' +
'<input type="button" name="delete[]" value="delete" id="delete"/></div>'
);
});
$('body').on('click', '#delete', function(e) {
event.preventDefault()
$(this).parent('div').remove();
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="bg-modal">
<div class="modal-contents">
<div class="close li:hoover">+</div>
<!-- validation todo -->
<form class="input-modal" id="kundInfo">
<br>
<input class="input-modal" type="text" placeholder="name" id="userName" required>
<input class="input-modal" type="email" placeholder="e-mail" id="userEmail" required>
<textarea class="input-modal" name="meddelande" placeholder="Övrig information" id="userMessage"></textarea>
<select class="input-modal" id="deliveryTown" value="">
<option value="default">Välj leveransort</option>
<option value="Stockholm">Stockholm</option>
<option value="Göteborg">Göteborg</option>
<option value="Kalmar">Kalmar</option>
</select>
<br>
<div id="dynamic-items">
<input class="dynamic-input-fields" type="text" name="artikel[]" placeholder="Artikel">
<input class="dynamic-input-fields" type="number" name="kvantitet[]" placeholder="kvantitet">
<input class="dynamic-input-fields" type="button" value="Lägg till" id="add">
<!-- (original submit button)
<input type="submit" value="submit">
-->
</div>
<br>
<select class="input-modal" id="produktKategori" value="">
<option value="default">Välj inköpskategori</option>
<option value="trävaror">Trävaror</option>
<option value="mur&puts">Mur & puts</option>
<option value="mark&trädgård">Mark & trädgård</option>
<option value="vvs">VVS</option>
<option value="våtrum">Våtrum</option>
<option value="verktyg">Verktyg</option>
</select>
<br>
<br>
<button class="input-modal" id="Skicka" type="submit">Skicka</button>
</form>
<div class="alert">Ditt förfrågan är skickad!</div>
</div>
</div>

Related

dropdown in input form not selecting

i have a simple form that has a drop down
<form action="TasksController#store" method="POST">
<div>
<div class="textbox-first" style="float:left">
<label for="taskname"> Task Name </label><br>
<input type="text" placeholder="Enter task title" name="title" style="width:360px">
</div>
<div class="textbox-first" style="float:right;margin-right:0px">
<label for="priority">Task priority</label><br>
<select style="width:380px">
<option value="urgent" selected="selected">Urgent</option>
<option value="important">important</option>
<option value="later">Later</option>
</select>
</div>
</div>
the form is not selecting

HTML search option with filters that link to external website

I'm required to use only HTML to create a web form in which the search result will link me to the external website's search results. There are search options with filters that I have included and when I enter the input and select the filters, it links me to the external website but it does not filter out the search from my own web form, meaning that it would treat any search as a normal search without the filters for 'month', '6months' and 'year' option.
https://www.worldscientific.com/search/advanced - The website that I am supposed to link the search result from my web form to.
HTML Code:
<html>
<style>
*{
box-sizing: border-box;
}
#border1 {
width: 1000px;
height: 500px;
padding: 15px;
border: 2px;
}
</style>
<h2>Part 3 - World Science</h2>
<form id="worldscience_search-form"
action="https://www.worldscientific.com/action/doSearch?field1=AllField&text1=text1&publication=&Ppub=&AfterMonth=&AfterYear=&BeforeMonth=&BeforeYear=&earlycite=on" method="get" target="_blank" class="jcf-select" autocomplete="off">
<div id="border1">
<div style = "float:left; width:20%">
<select id="textArea2" name="field1" style = "height:40px; width:120px;">
<option value="AllField">Anywhere</option>
<option value="Title">Title</option>
<option value="Contrib">Author</option>
<option value="Keyword">Keywords</option>
<option value="Abstract">Abstract</option>
</select>
<br><br><br>
<label for="publication">Published in</label> <br><br><br>
<label>Publication Date</label>
<input type="hidden" value="AfterYear">
<input type="hidden" value="BeforeYear">
<br>
</div>
<div style = "float:left; width:20%">
<input type="text" placeholder="Enter Search term" name="text1" style = "width: 500px; height:40px"><br><br>
<input type="text" name="publication" placeholder="e.g. Journal of Theoretical Biology" style = "width:500px; height :40px">
<br><br><br>
<input type="radio" name="Ppub" value="" checked="checked">
<label>All dates</label>
<br><br><br>
<input type="radio" name="Ppub" value="">
<label>Last</label>
<br><br><br>
<input type="radio" name="Ppub" value="">Custom Range
</div>
<div style = "float:left; width:50%">
<br><br><br><br><br><br><br><br><br><br>
<select id="Ppub" value="" style = "height:40px; width:120px;">
<option value="">Select</option>
<option value="20181218-20190118">month</option>
<option value="20180718-20190118">6 months</option>
<option value="20180118-20190118">year</option></select><br><br>
<input type="submit" value="Search" />
</div>
</form>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br>
</html>
I don't think that I should have coded the values in the option value. How am I supposed to filter out without coding in the dates?
You have to use hidden inputs: (I only show start of the form)
<form id="worldscience_search-form" action="https://www.worldscientific.com/action/doSearch" method="get" target="_blank" class="jcf-select" autocomplete="off">
<input type="hidden" name="field1" value="AllField">
<input type="hidden" name="text1" value="text1">
<input type="hidden" name="publication" value="">
<input type="hidden" name="Ppub" value="">
<input type="hidden" name="AfterMonth" value="">
<input type="hidden" name="AfterYear" value="">
<input type="hidden" name="BeforeMonth" value="">
<input type="hidden" name="BeforeYear" value="">
<input type="hidden" name="earlycite" value="on">

Enable and disable input field with select

I have a form, where I would like that the two input fields "CVR number" and "Telephone" is only enabled if the value is "Yes". (Se attached file which is the end result). The form is looking like this now: Example on my form
I tried to make something work with the below code, but I am not sure that I am on the correct track? The second input field is not getting active when I use yes.
What do you think?
HTML
<form>
<select id="mySelect" onChange="check(this);">
<option>No</option>
<option>Yes</option>
</select>
<input type="text" id="company" disabled="disabled" placeholder="CVR number">
<input type="text" id="company" disabled="disabled" placeholder="Telephone">
</form>
JS
function check(elem) {
document.getElementById('company').disabled = !elem.selectedIndex;
}
Updated HTML code
<h3>Do you want a company account?</h3>
<div class="form-group">
<select class="form-control" id="mce-COMPANY" name="COMPANY" id="mySelect" onChange="check(this);">
<option value="Nej">Nej</option>
<option value="Ja">Ja</option>
</select>
</div>
<input placeholder="CVR nummer" name="EMAIL" class="mail" type="text" id="mce-EMAIL" id="company1" disabled="disabled"></input>
<span class="icon4"><i class="fa fa-envelope" aria-hidden="true"></i></span>
<input placeholder="Telefonnummer" name="EMAIL" class="mail" type="text" id="mce-EMAIL" id="company2" disabled="disabled" ></input>
<span class="icon4"><i class="fa fa-envelope" aria-hidden="true"></i></span>
function check(elem) {
document.getElementById('company').disabled = !elem.selectedIndex;
}
<form>
<select id="mySelect" onChange="check(this);">
<option>No</option>
<option>Yes</option>
</select>
<input type="text" id="company" disabled="disabled" placeholder="CVR number">
<input type="text" id="company" disabled="disabled" placeholder="Telephone">
</form>
You have used the same ID for both the fields.
Use 2 different Ids and it works..
function check(elem) {
document.getElementById('company1').disabled = !elem.selectedIndex;
document.getElementById('company2').disabled = !elem.selectedIndex;
}
<form>
<select id="mySelect" onChange="check(this);">
<option>No</option>
<option>Yes</option>
</select>
<input type="text" id="company1" disabled="disabled" placeholder="CVR number">
<input type="text" id="company2" disabled="disabled" placeholder="Telephone">
</form>

How can i enable specific textboxes when a specific combo box option is chosen

Sorry but i'm new in html and i would like to ask how can i enable specific textboxes when a specific combo box option is chosen.
I've seen the topic how to activate a textbox if I select an other option in drop down box but i don't understoond what am i doing wrong.
I want when a combo box option such as option1 is selected to enable textboxes with the name lesson1, lesson2, lesson3, when a combo box option such as option2 is selected to enable textboxes with the name lesson4, lesson5, lesson6 etc for the user to fill.
Here is my code
function Select(val) {
var element=document.getElementById("options1");
var element2=document.getElementById("options2");
var element3=document.getElementById("options3");
if (val=="option 1"){
element.style.display="block";
else
element.style.display="none"; }
else if (val=="option2"){
element2.style.display="block";
else
element2.style.display="none"; }
else if (val=="option 3"){
element3.style.display="block";
else
element3.style.display="none"; }
}
<label class="formLabel">
Options*</label><br />
<select name="select2" required="" onchange="Select(this.value);">
<option disabled="disabled" selected="selected" value=""></option>
<option value="">option 1</option>
<option value="">option 2</option>
<option value="">option 3</option>
</select><br />
<div id="options1" style="display: none;">
<label class="classLabel">
lesson 1*
</label>
<label class="classLabel">
lesson 2*</label>
<label class="classLabel">
lesson 3*</label><br />
<input class="formText" name="field7" required="" type="text" />
<input class="formText" name="field8" required="" type="text" />
<input class="formText" name="field9" required="" type="text" /><br />
</div>
<div id="options2" style="display: none;">
<label class="classLabel">
lesson 4*
</label>
<label class="classLabel">
lesson 5*</label>
<label class="classLabel">
lesson 6*</label><br />
<input class="formText" name="field10" required="" type="text" />
<input class="formText" name="field11" required="" type="text" />
<input class="formText" name="field12" required="" type="text" /><br />
</div>
<div id="options3" style="display: none;">
<label class="classLabel">
lesson 7*
</label>
<label class="classLabel">
lesson 8*</label>
<label class="classLabel">
lesson 9*</label><br />
<input class="formText" name="field13" required="" type="text" />
<input class="formText" name="field14" required="" type="text" />
<input class="formText" name="field15" required="" type="text" /><br />
</div>
<input id="submitButton" type="submit" value="send" /></form> </div>
You have not added values to combo box , combo box must be like
<select name="select2" required="" onchange="Select(this.value);">
<option disabled="disabled" selected="selected" value=""></option>
<option value="option 1">option 1</option>
<option value="option 2">option 2</option>
<option value="option 3">option 3</option>
</select>
and there is some syntax error in your js script also
please try the following code
syntax of if else wrong
<script>function Select(val) {
var element=document.getElementById("options1");
var element2=document.getElementById("options2");
var element3=document.getElementById("options3");
if (val=="option 1")
element.style.display="block";
else
element.style.display="none";
if (val=="option 2")
element2.style.display="block";
else
element2.style.display="none";
if (val=="option 3")
element3.style.display="block";
else
element3.style.display="none";
}
</script>
<script>
function Select(val) {
var element=document.getElementById("options1");
var element2=document.getElementById("options2");
var element3=document.getElementById("options3");
if (val=="option 1")
element.style.display="block";
else
element.style.display="none";
if (val=="option 2")
element2.style.display="block";
else
element2.style.display="none";
if (val=="option 3")
element3.style.display="block";
else
element3.style.display="none";
}
</script>
<label class="formLabel">Options*</label><br />
<select name="select2" required="" onchange="Select(this.value);">
<option disabled="disabled" selected="selected" value=""></option>
<option value="option 1">option 1</option>
<option value="option 2">option 2</option>
<option value="option 3">option 3</option></select><br />
<div id="options1" style="display:none;">
<label class="classLabel">lesson 1* </label>
<label class="classLabel">lesson 2*</label>
<label class="classLabel" >lesson 3*</label><br />
<input class="formText" name="field7" required="" type="text" />
<input class="formText" name="field8 required="" type="text" />
<input class="formText" name="field9" required="" type="text" /><br />
</div>
<div id="options2" style="display:none;">
<label class="classLabel" >lesson 4* </label>
<label class="classLabel">lesson 5*</label>
<label class="classLabel" >lesson 6*</label><br />
<input class="formText" name="field10" required="" type="text" />
<input class="formText" name="field11" required="" type="text" />
<input class="formText" name="field12" required="" type="text" /><br />
</div>
<div id="options3" style="display:none;">
<label class="classLabel">lesson 7* </label>
<label class="classLabel">lesson 8*</label>
<label class="classLabel">lesson 9*</label><br />
<input class="formText" name="field13" required="" type="text" />
<input class="formText" name="field14" required="" type="text" />
<input class="formText" name="field15" required="" type="text" /><br />
</div>
<input id="submitButton" type="submit" value="send" /></form>
</div>

htm form to disappear after submission

I am a bit new to coding. I have made a HTML form which is posting to one website after submission and is also landing on the other page for acknowledgement. but my form page is not disappearing. i am using google sites for this form so cant use any scripting language. Have to rely on html only
<form action="https://www.salesforce.com/servlet/servlet.WebToCase?encoding=UTF-8" method="POST">
<!-- ---------------------------------------------------------------------- -->
<!-- NOTE: These fields are optional debugging elements. Please uncomment -->
<!-- these lines if you wish to test in debug mode. -->
<!-- <input type="hidden" name="debug" value=1> -->
<!-- <input type="hidden" name="debugEmail" value="smoiz88#gmail.com"> -->
<!-- ---------------------------------------------------------------------- -->
<label for="first_name">First Name</label>
<input id="first_name" maxlength="40" name="first_name" size="40" type="text" required />
<br>
<label for="last_name">Last Name</label>
<input id="last_name" maxlength="40" name="last_name" size="40" type="text" required />
<br>
<label for="email">Email</label>
<input id="email" maxlength="80" name="email" size="40" type="text" required />
<br>
<label for="phone">Phone</label>
<input id="phone" maxlength="40" name="phone" size="40" type="number" />
<br>
<label class="label">Site</label>
<select class="select" id="Site" name="site" title="Site">
<option value="None">None</option>
<option value="Armadale">Armadale</option>
<option value="Elsternwick">Elsternwick</option>
<option value="Hawthorn">Hawthorn</option>
<option value="Manila">Manila</option>
<option value="UK">UK</option>
<option value="Other">Other</option>
</select>
<br>
<br>
<label class="label">Salesforce Profile</label>
<select class="select" id="Profile">
<option value="None">None</option>
<option value="Acquire Career Champion">Acquire Career Champion</option>
<option value="Acquire Career Advisor">Acquire Career Advisor</option>
<option value="Acquire Career Hunter">Acquire Career Hunter</option>
<option value="Acquire Data Analyst">Acquire Data Analyst</option>
<option value="Acquire Retention Specialist">Acquire Retention Specialist</option>
<option value="Acquire Training Admin">Acquire Training Admin</option>
<option value="Acquire Qualifier">Acquire Qualifier</option>
</select>
<br>
<br>
<label for="fault">Fault Title</label>
<input id="fault" maxlength="20" name="fault" size="30" type="text" required />
<br>
<br>
<label>Fault Type</label>
<select class="select" id="Type">
<option value="None">None</option>
<option value="Password Reset">Password Reset</option>
<option value="Report Required">Report Required</option>
<option value="Login Details">Login Details</option>
<option value="End Of Employment">End Of Employment</option>
<option value="File Merge">File Merge</option>
<option value="Insufficient Privilege">Insufficient Privilege</option>
<option value="Other">Other</option>
</select>
<br>
<br>
<label for="description">Description</label>
<textarea name="description"></textarea>
<br>
<div id="submit">
<input type="submit" name="submit">
</div>
</form>
any suggestions how can i make it disapper once it is submitted.
It seems the server brings you back because it doesn't know where to redirect after form submission.
Try create another page with confirmation text and configure server to redirect there after submission.
There must be a parameter or something on the server side to control submission behavior.