Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I used this function for checking the url
<script type="text/javascript">
$(document).ready(function () {
if (window.location.href.indexOf("franky") > -1) {
/* some code to change the css */;
}
});
</script>
Currently it only works when I refresh the page.
Is there a way to make it work when url change without any refresh ? Thanks
EXAMPLE : its like you have to choose a color , you click on a button to select your color , it make example.com/color.html#/red ; example.com/color.html#/blue ; example.com/color.html#/black only the color change with no refresh and i want to add specific css when url contain each string color
black
blue
<script type="text/javascript">
$(window).on('hashchange', function(e){
var origEvent = e.originalEvent;
resultdata = origEvent.newURL;
var black = resultdata.match(/black/);
if (black){
console.log(black);
}
});
</script>
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
there is a simple order page on my website that I have prepared to improve myself.
When the order page is opened ,the" 1 piece " option is selected.
Do this " document.getElementById ('mark1').click () " I did it thanks to this code. But when you click on 1pc, you will see that it comes in their products.
My request is that 1 option is selected when the site is opened and the products are listed. How can I do this?
Page: https://fcproje.com/nike/siparis.php
Clicking that <input type='radio'> seems to trigger the following code on line 598 of your file
$("#mark1").on('click', function() {
var markalar = this.dataset.id;
var mainid=1;
if(markalar){
for (var i =1; i <= mainid; i++) {
sender(i,markalar);
}
}
});
You could simulate this code after the code you use to click on the radio button.
So change this line
document.getElementById('mark1').click()
To this block of code;
document.getElementById('mark1').click();
(function(){
var markalar = "1"; // The Dataset.id of the input was "1" so add it here
var mainid=1;
if(markalar){
for (var i =1; i <= mainid; i++) {
sender(i,markalar);
}
}
})();
The code is wrapped in an anonymous function as to not add unnecessary variables to the global window object.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I want to make a list in HTML and then the user selects the list and then do something with the selections.
For example. List of fruits. Apple bannana, grapes.
User selects grapes and if grapes is selected asked how many grapes?
I would like to know how i can do this in Javascript or Jquery
Use this code block. As simple as that,
//generates the list
var items = 'Apple, bannana, grapes';
var nHtml = '';
items = items.split(',');
items.forEach(function(v){
//trim() will remove the blank spaces
nHtml+='<li>'+ v.trim() +'</li>';
});
$('#itemList').append('<ul>'+ nHtml +'</ul>');
//detect click on the list item
$('li').click(function(){
var name = $(this).text();
var question = 'How many '+name+' ?';
$('#question').html('<span>'+ question +'</span><input type="text" id="answer" />')
});
//get the number feed into the text box
function getCount(){
var answer = $('#answer').val();
console.log(answer);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id='itemList'></div>
<div id='question'></div>
<button onclick='getCount()'>Get Count</button>
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a small project where i created text fields based on user input.
$('#arraySizeButton').click(function() {
var arraySize = $("#arraySize").val();
if(arraySize=='') {
alert("Enter Some Text In Input Field");
}else{
var count = arraySize;
var html = [];
while(count--) {
html.push("\<input type='text' id='inputTextField", count, "'>");
}
$('#inputTextFieldsarea').append(html.join(''));
}
});
I want to create a dynamic program based on above code and retrieve data from textfields to an array. Appreciate your help.
Did you mean this?
html.push("<input type='text' id='inputTextField"+count+"'/>");
What you should do is add a [] to the name of the input, to let the html form know that this is an array.
You should do something like that:
html.push("\<input name='field[]' type='text' id='inputTextField", count, "'>");
And using php to get the content of all the POSTed fields you could simply check
$_POST['field']
which is an array.
EDIT: IF you want to do this using jquery as you stated in your comment, then you could do it like that:
$('[id^="inputTextField"]').each(function() {
alert($(this).val());
});
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
$(document).ready(function(){
$("#sakla").click(function(){
$(".askforum").hide();
});
$("#getir").click(function(){
$(".askforum").show();
});
Hi ! how can I combine two button function to one button ? I want to run two functions with one button. the button name should change when I clicked if its show it must be become hide. thanks
Use toggle to toggle between shown and hidden. Change the two buttons into one button, and bind the click event to that button alone.
$(document).ready(function(){
var button = $('#thatnewbutton');
button.click(function(){
var forum = $(".askforum");
forum.toggle();
button.text(forum.is(':visible')?'Hide':'Show');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="thatnewbutton">Hide</button>
<div class='askforum'>Content</div>
Here is a simple demo:
$(function() {
$('.toggle').on('click', function() {
var txt = $(this).text().trim();
$(this).text( txt == 'HIDE' ? 'SHOW' : 'HIDE' );
$('.whattotoggle').toggle();
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<button class="toggle">HIDE</button>
<div class="whattotoggle">Toggle This</div>
$(document).ready(function(){
$("#thatnewbutton").click(function(){
$(".askforum").toggle();
});
});
Alternatively for changing the name, find attr name of the button and accordingly change it using attr function.
How can I set the Name attribute of an input field using Jquery?
Cheers!
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I want to create a form for my client. My client require to create a dynamic for him.
Suppose, I want to insert 1 record in main table of mysql, and record multiple records in secondary table which has reference key of main table. I don't know how many records against the main table, it maybe one at time or multiple records at time. I want to do it with single form. If client click add more button it show another text field to insert more data.
how I can do it ?????
It would be possible using pure javascript
like this
<input type="button" onclick="addInput()"/>
<span id="responce"></span>
<script>
var countBox =1;
var boxName = 0;
function addInput()
{
var boxName="textBox"+countBox;
document.getElementById('responce').innerHTML+='<br/><input type="text" id="'+boxName+'" value="'+boxName+'" " /><br/>';
countBox += 1;
}
</script>
This is possible through the jquery/javascript.
So you can use this reference :http://www.mkyong.com/jquery/how-to-add-remove-textbox-dynamically-with-jquery/
Just try it!!
here is the code:
function generateTextBox()
{
var mainDiv=document.getElementById('options');
alert(mainDiv);
var newBreak=document.createElement('br');
mainDiv.appendChild(newBreak);
for(var i=1;i<=4;i++)
{
var newTextBox=document.createElement('input');
var newBreak1=document.createElement('br');
var newBreak2=document.createElement('br');
var newBreak3=document.createElement('br');
var text = document.createTextNode("Option"+i);
newTextBox.type='text';
newTextBox.setAttribute('id','txtAddr'+i);
alert(newTextBox+"2");
mainDiv.appendChild(text);
mainDiv.appendChild(newTextBox);
mainDiv.appendChild(newBreak1);
mainDiv.appendChild(newBreak2);
mainDiv.appendChild(newBreak3);
}
}
This isn't php related, you'll need to dynamically add to the form using javascript.