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
am new to web development i have developed one website and now i want to place a text field on top corner and give options to pick a city and display content based on selected city. for example: in a web page i should have a text box, if i enter some city name it should display tat cities contents (use case: if i select Delhi it should display Delhi's content, if i select Mumbai it should display Mumbai's content how can i achieve this task ) any code, any references can be appreciated, Thanks in advance. (HTML, javascript, java anything is ok)
Here is something like what you want, you can make a popup instead of a dropdown if you want. Tell me if you need anymore help, or need to understand the code. This code is based of Dmitriy Lishtvan's answer for this question. I just made it relate to your question.
$(function(){
$('.selectOption').change(function(){
var selected = $(this).find(':selected').text();
//alert(selected);
$(".desc").hide();
$('#' + selected).show();
}).change()
});
.desc {display: none;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select class="selectOption">
<option>--Choose One---</option>
<option>Chennai</option>
<option>Washington</option>
<option>Hamburg</option>
</select>
<div id="changingArea">
<div id="Chennai" class="desc"><iframe height=900 width=900 src="https://en.wikipedia.org/wiki/Chennai"></iframe></div>
<div id="Washington" class="desc"><iframe height=900 width=900 src="https://www.washingtonpost.com"></iframe></div>
<div id="Hamburg" class="desc"><iframe height=900 width=900 src="https://www.tripadvisor.com/Tourism-g187331-Hamburg-Vacations.html"></iframe>
</div>
</div>
In Java you can use the TextField class to have the user input. Then you can use a JButton and then when the user clicks the button the corresponding content(Organize the content with an array).
Link to info about TextFields
https://docs.oracle.com/javase/tutorial/uiswing/components/textfield.html
Also JButton
https://docs.oracle.com/javase/tutorial/uiswing/components/button.html
Good Luck!
I think this is what you want
`http://jsfiddle.net/XCUDF/`
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 10 months ago.
Improve this question
<div class="main-div main-div2"> <!-- IF up to date, main-div3 -->
<button id="update-btn" class="btn update-btn">
Up to date
</button>
</div>
I want to make it so if update-btn has a value of "Up to date", change the div class from "main-div main-div2" to "main-div main-div3". Otherwise, if it's any other value, change it to "main-div main-div2"
What kind of loop would be good for this Javascript function too if I want it to be
checking constantly?
Thank you.
there are many method to do it, here is the basic idea that you can get it done.
var btnText = document.getElementById("update-btn").innerText
var divClass = document.getElementById("outer-div")
if(btnText == "Up to date"){
divClass.classList.remove("main-div2");
divClass.classList.add("main-div3");
}else{
divClass.classList.remove("main-div3");
divClass.classList.add("main-div2");
}
.main-div2{
background-color:red;
}
.main-div3{
background-color:blue;
}
<div id="outer-div" class="main-div main-div2">
<button id="update-btn" class="btn update-btn">
Up to date
</button>
</div>
checkout the above snippet, its checking the text In if condition and sets up the class for parent div according to the text in the button, you can read more about adding and removing class from here
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'm trying to make a website. But I need to make a syntax highlighting program that Categorize commands based on what they do. For example, one group would be I/O, another one would be Control commands. And you would color the text based off of what type of command it is. Please I need help.
<html>
<head>
<div class=“io”>Text goes here</div>
div.io {
color: #0A0A0A;
</head>
<!--
PREFIX = 'lang/'
SUFFIX = '.js'
-->
<body onload="sh_highlightDocument('lang/', '.js');">
<!--
CLASS = 'sh_java'
PREFIX + CLASS + SUFFIX = 'lang/' + 'sh_java' + '.js'
= 'lang/sh_java.js'
-->
<pre class="sh_java">
public class X {}
</pre>
</body>
</html>
There are a few problems with your code above:
You are writing your <div> in the <head> section, which is invalid HTML
You are using curly “ ” quotes on your <div> class declaration, which won't work
In addition to this, your question is incredibly vague. There don't appear to be any 'control commands' in your question.
Having said that, it sounds like you're trying to turn the text in the io class red, and some additional content in a control-commands class green.
This can be done with JavaScript's .getElementsByClassName() method and .style property as follows:
function change() {
document.getElementsByClassName('io')[0].style.color = 'red';
document.getElementsByClassName('control-commands')[0].style.color = 'green';
}
<div class='io'>IO</div>
<div class='control-commands'>Control Commands</div>
<br />
<button onclick="change()">Change</button>
Keep in mind that .getElementsByClassName returns a Node List, so you need to access the first index of that with [0] as above.
Hope this helps!
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 8 years ago.
Improve this question
The customer asked for the prices to not be visible for each product on the e-shop until the customer clicks on a button. So far jQuery/javascript, as a solution to this, seem more appropriate, I was wondering if there is something else I am missing (code wise, in PHP for example) that would help out more.
I request you to post what you have tried before asking in SO in future!
though Solution is here
<div class="product-image">
<p class="prod-name">Product Name</p>
<p class="prod-price" style="display:none" >$1000</p>
<input type="button" class="show-price" value="show price"/>
</div>
Css
.product-image{
border:1px solid #ccc;
width:100px;
height:100px;
background-color:#f6f6f6;
}
.prod-name,.prod-price{
font-size:12px;
text-align:center;
}
JS
$('.show-price').click(function(){
$(this).hide();
$('.prod-price').show();
});
Working fiddle here http://jsfiddle.net/raghuchandrasorab/njt1sfew/1/
Sure also works just with php but the page would need to refresh so i recommend using Javascript onclick event that show a hidden field when activated.
Not sure if this answers your question since im not quite sure what it was.
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 8 years ago.
Improve this question
i have two div's and i want to select first upper div value then lower div value. and pass both the values to next page.
here's my code:
<div id="upper">
Link
</div>
<div id="lower">
Link 1
</div>
if upper value is not selected then it should not go to the next page and when both values are selected then it should go on to next page.
what are the possible solutions.
Any help would be appreciated.
html
<span class="span_to_remember" data-my-data="myData1">
data1
</span>
<span class="span_to_remember" data-my-data="myData2">
data2
</span>
<span class="span_to_remember" data-my-data="myData3">
data3
</span>
<span class="span_to_remember" data-my-data="myData4">
data4
</span>
js(jquery)
$(document).ready(function(){
$(".span_to_remember").click(function() {
var spanData = $(this).data("my-data");
// also you can grab html with
// var spanData = $(this).html();
localStorage.setItem('param1', spanData);
});
});
after you write something on first page, you can read it on other page with
localStorage.getItem('param1');
info will be available for user on every page, even if he close browser, and return to website later
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 8 years ago.
Improve this question
I am a beginner to Javascript. Sorry for asking here, but I couldn't find a tutorial for this, and I hope someone can point me in the right direction.
I have an HTML page that has an unordered list on it. I have an input form that allows the user to submit a message. When the user submits a message, I want it to be added to the unordered list. This will be a permanent change to the website.
How do I make Javascript interact with the HTML like that?
---- Example:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<ul>
<li>example 1</li>
<li>example 2</li>
</ul>
<form>
<input type='text' name='Message' value="">
<input type='submit'>
</form>
</body>
</html>
The question's a little vague and I think it would be helpful to understand the concepts rather than have the specific code.
What you're trying to achieve, if you just want to manipulate the HTML using javascript, is to have an understanding of how JS can work with the DOM.
You do this by targeting elements. And you can target them either by their element type (div), a CSS classname, or most commonly by an id tag attribute.
In the example you've got above, when you submit the form you will need to call a function that will target the message input, grab its value. Then target the unordered list and append the HTML to the end of it containing the new message.
Since you're new, I would recommend learning jQuery. It'll get you up and running pretty quickly and you won't have to deal with as much diversity in varying browser implementations.
This will be a permanent change to the website.
NO this wont be..you probably need to store them in you db then.Following is just a demo of how to append to unordered list
HTML,
<ul id='message'>
<li>msg 1</li>
<li>msg 2</li>
</ul>
<form onsubmit='appendMessage(); return false;'>
<input type='text' id='message_text' value="" />
<input type='submit' />
</form>
JS
function appendMessage() {
var node = document.createElement("LI");
var message = document.getElementById('message_text').value;
var textnode = document.createTextNode(message);
node.appendChild(textnode);
document.getElementById("message").appendChild(node);
}
DEMO
var button = document.getElementsByTagName("input")[1];
button.onclick = function (){
var ul = document.findElementByTagName("ul")[0];
var li = document.createElement("li");
li.appendChild(document.createTextNode(this.value));
ul.appendChild(li);
};
Perhaps you could use LocalStorage and some of the functions above to archive that.
Here are a few examples of how to use LocalStorage and how to handler with objects(html tags with content for example).
http://coding.smashingmagazine.com/2010/10/11/local-storage-and-how-to-use-it/
Storing Objects in HTML5 localStorage
The drawnback´s are the support for older browsers and that the changes will only be available for the client where the changes where made.
The best aproach, it´s to combine the changes in javascript with some kind of storage(localstorage, SQL, NoSQL)
http://www.mongodb.org/ <--- NoSQL database