Multiple jQuery Pop-up Forms: Connect a href to <form> divs for user input - forms

I'm working on a digital textbook feature that would allow the student to click a link to open up a simple div form for them to input their answer to that specific question. The pop-up form is just simple HTML/CSS with some jQuery UI to hide, show, and make it draggable. Here's the twist. I've got multiple questions that each need to be attached to a unique div. No problem, I thought. I'll just set each a href to link back to a unique ID that I've assigned within the DIV. Problem is, I can't seem to target the proper DIV with its corresponding a href. Instead the same set of questions appear no matter which link is clicked. This seems super simple and I'm probably overcomplicating it. What can I do here?
HTML:
<div id="draggable" class="messagepop pop">
<form method="post" id="new_message" action="/answers">
<p><label for="body">What type of person is Carsten?</label><textarea rows="15" name="body" id="body" cols="55"></textarea></p>
<p><label for="body">How do you know?</label><textarea rows="15" name="body" id="body" cols="55"></textarea></p>
<p><center><input type="submit" value="Submit" name="commit" id="message_submit"/> or <a id="hide" href="#">Cancel</a></center></p>
</form>
</div>
<div id="draggable" class="messagepop pop">
<form method="post" id="new_message" action="/answers">
<p><label for="body">What can you learn about an active volcano from the photograph?</label><textarea rows="15" name="body" id="body" cols="55"></textarea></p>
<p><center><input type="submit" value="Submit" name="commit" id="message_submit"/> or <a id="hide" href="#">Cancel</a></center></p>
</form>
</div>
Draw Conclusions What kind of person is Carsten? How do you know?
Use Text Features What can you learn about an active volcano from the photograph?
Where the first a href needs to open the first div and the second a href opens the second div, etc., etc.
CSS:
.messagepop {
overflow-y: auto;
overflow-x: hidden;
cursor:default;
display:none;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
text-align:left;
width:394px;
height: 335px;
z-index:50;
padding: 25px 25px 20px;
background-color: #fff;
-moz-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
-moz-border-radius: 4px 4px 4px 4px;
-webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
-webkit-border-radius: 4px 4px 4px 4px;
border-color: #E5E5E5 #DBDBDB #D2D2D2;
border-style: solid;
border-width: 1px;}
JS:
$(document).ready(function() {
$('.show').click(function() {
if ( !$(this).next('div').is(':visible') ) {
$(".messagepop").slideFadeToggle();
$(this).next('div').slideFadeToggle();
}
});
$('.hide').click(function() {
$(this).parent().slideFadeToggle();});
$.fn.slideFadeToggle = function(easing, callback) {
return this.animate({ opacity: 'toggle', height: 'toggle' }, "fast", easing, callback);};
$(function() {
$("#draggable").draggable();});

Thank you for your advice and for ironing out my poorly written method. It seems you've got it working.
I've since discovered a jQuery Mobile solution that is much easier than what I was trying to pull together.
For future viewers, it would simply look like this.
Draw Conclusions
Use Text Features
<div data-role="popup" id="popup1" class="ui-content" data-position-to="window">
Close
<p>What kind of person is Carsten?</p>
<input type="text"/>
<p>How do you know?</p>
<textarea></textarea>
</div>
<div data-role="popup" id="popup2" class="ui-content" data-position-to="window">
Close
<p>What can you learn about an active <mark><b>volcano</b></mark> from the photograph?</p>
<textarea></textarea>
</div>
The logic here makes a lot more sense to me and there's the added benefit of ensuring it will work properly on mobile devices. Then if you want to make it draggable, just drop in:
<script>
$(function() {
$(".ui-content").draggable();
});
</script>
And then if you want it to be draggable on mobile (remember, jQuery UI isn't natively supported on mobile), you'll have to call up a hack of sorts. I like Touch Punch.
You may run into issues with form inputs when using Draggable combined with Touch Punch, but that's a story for another thread.

Here is a demo: http://jsfiddle.net/ebNsz/
I've set id:s for the question-div:s and target them with the 'href' attribute in the 'a' elements. Not sure what you wanted to do with the 'slideFadeToggle' function, so i used 'fadeToggle' instead.
HTML:
<div id="q1" class="messagepop">
<form method="" id="form1" action="/answers">
<label for="answer1">What type of person is Carsten?</label><textarea name="answer1" class="answer"></textarea>
<label for="answer2">How do you know?</label><textarea name="answer2" class="answer"></textarea>
<div>
<input type="submit" value="Submit" name="submit" /> or <a class="close" href="">Cancel</a>
</div>
</form>
</div>
<div id="q2" class="messagepop">
<form method="" id="form2" action="/answers">
<label for="answer1">What can you learn about an active volcano from the photograph?</label><textarea name="answer1" class="answer"></textarea>
<div>
<input type="submit" value="Submit" name="submit" /> or <a class="close" href="">Cancel</a>
</div>
</form>
</div>
<p>Draw Conclusions What kind of person is Carsten? How do you know?</p>
<p>Use Text Features What can you learn about an active volcano from the photograph?</p>
jQuery: (jsFiddle doesn't support .draggable(), so i commented out the first line and added the second.)
$(function() {
/* $("div.messagepop").draggable().hide();*/
$("div.messagepop").hide();
$("a.toggle").click(function(e)
{
e.preventDefault();
var targetpop = $(this).attr('href');
$(targetpop).siblings("div.messagepop").fadeOut();
$(targetpop).fadeToggle();
});
$("a.close").click(function(e)
{
e.preventDefault();
$(this).closest("div.messagepop").fadeToggle();
});
});
CSS:
.messagepop {
position: absolute;
top: 20%;
left: 50%;
z-index: 50;
margin-left: -197px;
text-align: center;
width: 394px;
height: 335px;
padding: 25px 25px 20px;
background-color: #fff;
-moz-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
-webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
border-color: #E5E5E5 #DBDBDB #D2D2D2;
border-style: solid;
border-width: 1px;
}
label {
display: block;
}
textarea {
width: 75%;
height: 5em;
margin: 0 0 1em 0;
}

Related

Disable similar results from list.js

I use list.js, but it displays also similar results. For example I am typing Mar..., website displays also mur, car, man and etc. How can I disable them?
It is demo from codepen:
<p class="codepen" data-height="265" data-theme-id="0" data-default-tab="html,result" data-user="javve" data-slug-hash="isInl" style="height: 265px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;" data-pen-title="List.js - Fuzzy search">
<span>See the Pen <a href="https://codepen.io/javve/pen/isInl/">
List.js - Fuzzy search</a> by Jonny Strömberg (#javve)
on CodePen.</span>
</p>
<script async src="https://static.codepen.io/assets/embed/ei.js"></script>
You are using fuzzy-search, if you change <input type="text" class="fuzzy-search" /> to <input type="text" class="search" /> it works.
check it Codepen

creating multiple div elements in <b-card>

I would like to add 3 div elements in a top section of a card where currently there is an image. I would like to add an image, logo and text message in place of that image. What can I do???
Thanks in Advance,
Here's my code
1)HTML
<div class="card">
<b-card no-body
style="width: 20rem;"
img-src="https://placekitten.com/380/200"
>
<b-list-group class="group">
<b-list-group-item>Anvay Joshi</b-list-group-item>
<b-list-group-item>Computer</b-list-group-item>
<b-list-group-item>A-1103</b-list-group-item>
<b-list-group-item>30-11-1997</b-list-group-item>
<b-list-group-item>anvay.joshi#viit.ac.in</b-list-group-item>
<b-list-group-item>9766583977</b-list-group-item>
</b-list-group>
<b-button href="#" variant="primary">QR Code</b-button>
</b-card>
2)CSS
.group {
text-align: center;
}
.header{
text-align: center;
}
.card {
margin: 25px 120px 25px 240px;
border: none;
}
My Actual output looks like as shown
/Users/anvayjoshi/Desktop
My expected output is the top part of the card as shown
/Users/anvayjoshi/Desktop
Please help me !!!!!
Instead of using the img-src attribute on b-card, you can just add a new b-list-group-item.
Here's a jsfiddle demonstrating that, and an image of the result.
new Vue({
el: "#app",
data: {
}
});
.image {
float: left;
}
.logo {
float: left;
margin-right: 10px;
margin-left: 10px;
margin-top: 20px;
}
.text {
float: left;
width: 100px;
}
.group {
text-align: center;
}
.header {
text-align: center;
}
.card {
margin: 10px;
border: none;
}
<div id="app">
<div class="card">
<b-card no-body style="width: 20rem;">
<b-list-group class="group">
<b-list-group-item>
<img class="image" src="https://placekitten.com/100/100" />
<img class="logo" src="https://placekitten.com/50/50" />
<div class="text">
Vishwakarma Institute of Information Technology
</div>
</b-list-group-item>
<b-list-group-item>Anvay Joshi</b-list-group-item>
<b-list-group-item>Computer</b-list-group-item>
<b-list-group-item>A-1103</b-list-group-item>
<b-list-group-item>30-11-1997</b-list-group-item>
<b-list-group-item>anvay.joshi#viit.ac.in</b-list-group-item>
<b-list-group-item>9766583977</b-list-group-item>
</b-list-group>
<b-button href="#" variant="primary">QR Code</b-button>
</b-card>
</div>
</div>

How to make a span icon features as a submit button?

I founded some search-form with no button, they have the search icon featured as a submit button.
Normally they have html and css like this:
<form method="get" action="search.php">
<input type="text" class="" placeholder="search" name="s">
<span class="icon-search"></span>
</form>
span {
bottom: 0;
cursor: pointer;
line-height: 40px;
opacity: 0.3;
position: absolute;
right: 0;
text-align: center;
top: 1px;
width: 40px;
}
And it displays like this:
This span icon is clickable and works as submit button. How does it work?

Add span inside form's placeholder

I wanna add a color asterix in my form's placeholder, is it possible?
Here is pure css solution IE10+
.input-placeholder {
position: relative;
}
.input-placeholder input {
padding: 10px;
font-size: 25px;
}
.input-placeholder input:valid + .placeholder {
display: none;
}
.placeholder {
position: absolute;
pointer-events: none;
top: 0;
bottom: 0;
height: 25px;
font-size: 25px;
left: 10px;
margin: auto;
color: #ccc;
}
.placeholder span {
color: red;
}
<form novalidate>
<div class="input-placeholder">
<input type="text" required>
<div class="placeholder">
Email <span>*</span>
</div>
</div>
<input type="submit">
</form>
At first glance it doesn't seem possible, but it may be a good alternative to create your own fake spanholder element:
<div class="holder">Email Address <span class="red">*</span></div>
<input id="input" size="18" type="text" />
Fiddle
As far as I know, this is not possible.
One solution I have seen used in the past is to add a background-image of a red asterisk to your input field, but that makes it difficult to duplicate the visual alignment you are going for. More info on this method: Use CSS to automatically add 'required field' asterisk to form inputs
Another solution would be to add the span (and placeholder text) outside of the input field, but that would require some JavaScript to control when it is and isn't visible.
Here is a JSFiddle I just created for this method (using jQuery): http://jsfiddle.net/nLZr9/
HTML
<form>
<div class="field">
<label class="placeholder" for="email">
Email Address
<span class="red">*</span>
</label>
<input id="email" type="text" />
</div>
</form>
CSS
.field {
position: relative;
height: 30px;
width: 200px;
}
input, label {
position: absolute;
top: 0;
left: 0;
bottom: 0;
top: 0;
background: transparent;
border: 0;
padding: 0;
margin: 0;
text-indent: 5px;
line-height: 30px;
}
JS
$('.field input')
.on( 'focus', function () {
$(this).siblings('label').hide();
} )
.on( 'blur', function () {
if ( !$(this).val() )
$(this).siblings('label').show();
} );
You can try the following :
HTML
<div class="hold">
<input type="text" placeholder="" required="required">
<span class="req_placeholder">Name <span>*</span></span>
</div>
CSS
.hold {
position: relative;
}
input[required="required"]:valid + .req_placeholder {
display: none;
}
.req_placeholder {
position: absolute;
top: 2px;
left: 2px;
}
.req_placeholder span {
color: red;
}
I found a jQuery plugin that might suit you, the pholder plugin.
If you look the demo, the placholder of the "Name" field is red.
There may be other plugins or maybe you can edit it. :)
This is a good case for pseudo-elements.
.someclass {
position:relative;
}
.someclass:after {
position:absolute;
top:0;
right:10px;
content: "*";
color:#ff0000
}
...adjust to your own layout.
You can use pseudo elements in CSS (not supported in old browsers)
.mandatory::-webkit-input-placeholder { /* WebKit, Blink, Edge */
color: #ff0000;
}
.mandatory:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
color: #ff0000;
}
.mandatory::-moz-placeholder { /* Mozilla Firefox 19+ */
color: #ff0000;
}
.mandatory:-ms-input-placeholder { /* Internet Explorer 10-11 */
color: #ff0000;
}
.mandatory:placeholder-shown { /* Standard (https://drafts.csswg.org/selectors-4/#placeholder) */
color: #ff0000;
}
<form>
<p>
<label for="input1">Input 1:</label>
<input type="text" id="input1" placeholder="Fill input" class="mandatory" />
</p>
<p>
<label for="input2">Input 2:</label>
<input type="text" id="input2" placeholder="Fill input" />
</p>
<p>
<label for="textarea">Input 2:</label>
<textarea id="textarea" placeholder="Fill textarea"></textarea>
</p>
</form>

How to fix transparent div child in parent?

I have the CSS declare bellow:
#loadingBox-holder
{
height:100%;
width:100%;
position:fixed;
left:0;
top:0;
filter: alpha(opacity=30);
filter: progid:DXImageTransform.Microsoft.Alpha(opacity=30);
opacity:0.7;
-moz-opacity: 0.7;
z-index: 1000;
background-color:#000;
}
#loadingBox
{
position: fixed;
left: 40%;
top: 50%;
z-index: 1000;
height: 36px;
width: 138px;
border:1px solid #ccc;
background:#fff !important;
padding:5px 5px 10px 10px;
opacity:100;
/*-moz-opacity: 100 !important; */
}
and HTML:
<div id="loadingBox-holder" style="">
<div id="loadingBox">
<p>Please wait...</p>
<img src="../Images/loading.gif" alt="" />
</div>
</div>
The code above is a loadding indicator. My problem is the loadingBox-hold is gray transparent but I want the loadingBox is normal not transprent. I add the css bellow:
filter: alpha(opacity=100);
filter: progid:DXImageTransform.Microsoft.Alpha(opacity=100);
opacity:1;
-moz-opacity: 1;
However the child div still transparent.
Where is my mistakes and how to fix that ?
Thanks !
If you are using position fixed then moving loadingBox out of holder would not make any difference in the final output and it'll fix your opacity issue.
<div id="loadingBox-holder" style="">
</div>
<div id="loadingBox">
<p>Please wait...</p>
</div>
​
DEMO